嗨,我不明白爲什麼這段代碼沒有將數據從html文本插入到我的實際數據庫中。我正在嘗試僅使用First_Name對其進行採樣以開始。嘗試將表單信息發送到數據庫PHP/MYSQL
不管怎麼說HTML代碼如下:
<form action="Proform.php" name="Myform" method="post">
<input type ="hidden" value="1" name="check_submit" />
Please Enter First Name: <input type ="text" name="First_Name" /> <br />
Please Enter Second Name: <input type ="text" name="Second_Name" /><br />
Please Enter Email Address: <input type ="text" name="Email_Address" /><br />
Please Enter A Password: <input type="password" name="Password" /><br />
<input type ="submit" name"Submit" /><br />
</form>
和PHP,併爲隨後MYSQL:
<?php
$dbname='ecig';
$dbhost='localhost';
$dbpass='password';
$dbuser='eciguser';
$dbhandle = mysql_connect($dbhost, $dbuser, $dbpass)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$selected = mysql_select_db("ecig",$dbhandle)
or die("Could not select examples");
$res=mysql_query("INSERT INTO Persons (First_Name, Second_Name) VALUES ('$_POST[First_Name]')");
if (array_key_exists ('check_submit', $_POST))
echo "Your Name is : {$_POST['First_Name']}<br />";
echo "Your Second Name is : {$_POST['Second_Name']}<br />";
echo "Your Email Address is : {$_POST['Email_Address']}<br />";
echo "Your Password Is : {$_POST['Password']}<br />";
?>
它必須有一些做這一行的代碼,但我無法發現它。你們中的任何一個人都可以發現哪裏出了問題?
$res=mysql_query("INSERT INTO Persons (First_Name, Second_Name) VALUES ('$_POST[First_Name]')");
任何幫助將不勝感激。謝謝 。
歡迎來到Stack Overflow!請不要使用'mysql_ *'函數來編寫新的代碼。他們不再被維護,社區已經開始[棄用流程](http://news.php.net/php.internals/53799)。看到[紅色框](http://uk.php.net/manual/en/function.mysql-connect.php)?相反,您應該瞭解[準備好的陳述](http://en.wikipedia.org/wiki/Prepared_statement)並使用[PDO](http://php.net/pdo)或[MySQLi](http:// php.net/mysqli)。如果你選擇PDO [這裏是一個很好的教程](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers)。 – War10ck 2013-03-26 12:35:13