當用戶在我的網站上註冊時,他們需要輸入個人信息。輸入的詳細信息將被添加到我的數據庫中的personaldetails表中。我有下面的代碼,但它不起作用,我不明白爲什麼。誰能幫忙?我得到錯誤:查詢是空的在數據庫中插入發佈的詳細信息
$myusername=$_POST['username'];
$mypassword=$_SESSION['mypassword'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$dob = $_POST['dob'];
$totalwins = $_POST['totalwins'];
$totalloses = $_POST['totalloses'];
$email = $_POST['email'];
$country = $_POST['country'];
$info = $_POST['info'];
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$queryreg = mysql_query("
INSERT INTO $tbl_name VALUES('','','$myusername','$mypassword''$firstname','$surname','$totalwins','$totalloses','$email','$country','$info','$dob')
");
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
else {
echo "<br><br>Your details have been successfully updated. Go back to the personal details page to view your updated information.";
}
我們沒有魔法球..這是錯誤? – dynamic
請停止使用古代mysql_ *函數編寫新代碼。他們不再被維護,社區已經開始了貶值過程。相反,您應該瞭解準備好的聲明並使用PDO或MySQLi。 (你現在的代碼很容易被sql注入) – Bono
請停止使用古老的'mysql_ *'函數編寫新代碼。他們不再被維護,社區已經開始[棄用流程](http://goo.gl/KJveJ)。相反,您應該瞭解[準備好的語句](http://goo.gl/vn8zQ)並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli的)。如果你不能決定,[本文](http://goo.gl/3gqF9)將有助於選擇。如果你關心學習,[這裏是一個很好的PDO相關教程](http://goo.gl/vFWnC)。 – vascowhite