下面是代碼: contact_us2.php什麼都不會插入到我的數據庫
<form id="form1" method="post" action="enquires.php">
<fieldset>
<legend>Form to database example</legend>
<label for="text">
<span>Comments:</span>
<textarea id="text" name="comments" rows="4" cols="80"></textarea>
</label>
<label for="name">
<span>Name:</span>
<input id="name" type='text' name='name' size='50'/>
</label>
<label for="email">
<span>Email:</span>
<input id="email" type='text' name='email' size='50'/>
</label>
<label for="submit1" id="submit"><span> </span>
<input id="submit1" class="submit" type="submit" name="submit" value="Submit"/>
</label>
</fieldset>
</form>
enquires.php
<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);
require('authenticate.php');
include_once"../scripts/connect_to_mysql.php";
$name = $_post['name'];
$email = $_post['email'];
$comments = $_post['comments'];
echo "$email";
// Query the body section for the proper page
mysql_select_db("hardware_cms")or die (mysql_error());
$sqlCommand = MYSQL_QUERY("INSERT INTO enquires (id, name, email, comments)". "VALUES ('NULL', '$name', '$email', '$comments')") or die (mysql_error());
?>
沒有錯誤。插入數據庫的唯一東西是id。我認爲這個問題在contact_us2.php中。如果這是一個愚蠢的問題,我是新來的HTML和PHP抱歉。
請不要在新代碼中使用'mysql_ *'函數。他們不再被維護,社區已經開始[棄用流程](http://news.php.net/php.internals/53799)。看到[**紅框**](http://php.net/mysql-connect)?相反,您應該瞭解[準備好的陳述](http://en.wikipedia.org/wiki/Prepared_statement)並使用[PDO](http://php.net/pdo)或[MySQLi](http:// php.net/mysqli)。如果你不能決定,試試[這篇文章](http://php.net/mysqlinfo.api.choosing)。如果你關心學習,[這裏是很好的PDO教程](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers)。 –
謝謝你,爲什麼我的代碼不起作用? – user1680558
@ user1680558這不是它無法正常工作的原因,但是足夠重要的是可以立即停止正在執行的操作,並閱讀Mihai建議的內容並使用其中一種方法執行數據庫查詢。 – NightHawk