当用户在我的网站上注册时,他们需要输入个人信息。输入的详细信息将被添加到我的数据库中的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