各位大大您好:
php7.0+mysql+IIS
想請問寫一個報名表單(testsign.html),然後用test.php網頁寫回資料庫,我用PDO在test.php寫回資料庫,可是
回傳的訊息是變數變數未定義,本來是想說用testsign.html的name當變數在test.php,可是
無法成功,想請問是甚麼問題,謝謝!
Notice: Undefined variable: u_name in D:\eehome\key\test.php on line 17
Notice: Undefined variable: u_lab in D:\eehome\key\test.php on line 17
Notice: Undefined variable: u_phone in D:\eehome\key\test.php on line 17
Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean in D:\eehome\key\test.php:19 Stack trace: #0 {main} thrown in D:\eehome\key\test.php on line 19
testsign.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<div id="header">
<ul>
<li><a href="http://www.ee.nsysu.edu.tw/key/key_login.html"target="_blank"><font color="#000000">
管理者登入</font></a></li>
<li><a href="mailto:mayyola@mail.ee.nsysu.edu.tw"><font color="#000000">連絡我們</font></a></li>
</ul>
</div>
<div id="content_p">
<form name="f1" method="post" action=test.php>
<table width="600px" height="400px">
<p>姓名:<input type="text" name="name" size="10">
<p>借用人聯絡電話:<input type="text" name="phone" size="10"></p>
<p>實驗室鑰匙編號</p>
<input type="checkbox" name="lab" value="EC6018">EC6018
<input type="checkbox" name="lab" value="EC6023">EC6023
<input type="checkbox" name="lab" value="EC6027">EC6027
<p><input type="submit" style="background-color:#55AA00" value="確定"><input type="reset" value="重新設定"></p>
</form>
</table>
</div>
</html>
test.php
<?php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>哈哈</title>
</head>
<body>
<?php
header('Content-Type:text/html;charset=utf8');
$dsn = 'mysql:host=localhost;dbname=test'; //數據庫類型是mysql,主機地址是localhost,數據庫名稱是test
$pdo = new PDO($dsn, 'root','nsysuee1!');//初始化一個PDO對象,構造函數的參數第一個就是我們的數據源,第二個是連接數據庫服務器的用戶,第三個參數是密碼
$pdo->query("SET NAMES 'utf8'");
/*print_r($pdo->errorinfo());
echo $pdo->errorCode();*/
//$sql = "SELECT * FROM list "; //連接資訊
$u_name=$_POST['name'];
$u_phone=$_POST['phone'];
$data_array[]=array
(
"name"=>$u_name,
"phone"=>$u_phone
);
echo json_encode($data_array);
$sql = "insert into list(nanem,phone) values ('$u_name','$u_phone')";
$query = $pdo->query($sql); //執行 SQL
/*$query->setFetchMode(PDO::FETCH_ASSOC);// 設定查詢結果的資料格式,之後可以省去 fetch 時的格式設定
foreach($query as $row ){ // foreach 迴圈
echo "<td>";
echo $row['name'],' ';
echo "</td>";
echo $row['lab'],' ';
echo $row['phone'],' ';
echo $row['usrtime'],' ';
echo $row['return'],' <br>';
}*/
?>
</body>
剛有修改程式,不知道用checkbox的lab會出錯..先刪掉就OK,但寫不回去資料庫- -",我在phpmyadmin 打sql語法就可以新增..