这是一个私人讯息系统。它应该是将数据插入表中,但它根本不是......感谢您的帮助。
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'";
答案 0 :(得分:2)
您在列列表后错过了)
。请不要使用mysql_
函数。将准备好的语句与mysqli
或PDO
一起使用,如下所示:
$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')";