爲什麼我無法在我的數據庫中插入?這是我的代碼提交表格時出錯
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$bdate = $_POST['bdate'];
$id = $_POST['id'];
if (!empty($name) && !empty($email)){
mysql_query("insert into customer(id,name,email,bdate) values($id,'$name','$email','$bdate')");
}
else {
echo "Please fill <strong>name</strong> and <strong>e-mail</strong> fields!";
}
?>
我的形式是
<form method="post" action="new_customer.php">
ID: <input type="text" name="id" size="5" value="<?php echo $new_id; ?>" disabled="disabled" /><br />
Name: <input type="text" name="name" size="50" /><br />
E-mail: <input type="text" name="email" size="30" /><br />
Birth Date: <input type="text" name="bdate" size="10" /><br /><br />
<input type="submit" value="Save" />
</form>
的變量$ NEW_ID充滿了該查詢
SELECT (Max(id) + 1) as new_id FROM customer
但是,當我提交表單,我得到的錯誤是:
Notice: Undefined index: id in F:\UniServer\www\admin\customer.php on line 6
然後mysql錯誤
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '')' at line 1
我認爲第一個錯誤會導致secund,對嗎?
什麼是id如果它是你的自動增量id然後刪除它並嘗試 – 2011-12-16 13:03:28