php MySQL应该正常工作

时间:2012-09-06 02:38:33

标签: php mysql sql

这是一个私人讯息系统。它应该是将数据插入表中,但它根本不是......感谢您的帮助。

Sql Error :您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'from,body,subject,date_sent VALUES('itunes89','itunes89','sd','s','9-05-2012'附近使用正确的语法在第1行

$sql = "INSERT INTO pm_inbox (to_user, from, body,subject,date_sent)VALUES('$userIdFromPost','$user','$body','$sub','$date')";
mysql_query($sql);
echo "Error: " . mysql_error($con);
echo "<br/>Inserted: '$userIdFromPost','$user','$body','$sub','$date'";

2 个答案:

答案 0 :(得分:2)

您在列列表后错过了)。请不要使用mysql_函数。将准备好的语句与mysqliPDO一起使用,如下所示:

$stmt = $mysqli->prepare("INSERT INTO pm_inbox (to_user, from, body, subject, date_sent) VALUES(?,?,?,?,?)"); 
$stmt->bind_param($userIdFromPost,$user,$body,$sub,$date);

此外,from是MySQL中的reserved name。它需要像这样包围:

(to_user, `from`, body, subject, date_sent)

答案 1 :(得分:1)

你错过了一个右括号:

$sql = "INSERT INTO pm_inbox (to_user, from, body, subject, date_sent VALUES('$userIdFromPost','$user','$body','$sub','$date')";

应该是

$sql = "INSERT INTO pm_inbox (to_user, from, body, subject, date_sent) VALUES('$userIdFromPost','$user','$body','$sub','$date')";