我最近创建了一个PHP / MySQL评论系统,它几个小时前一直工作(代码中根本没有变化)。当我告诉提交表单代码回显查询时,它显示缺少commenttext和date的区域。我不明白为什么。这是我的代码:
mysql_connect("localhost","commentUser","password"); mysql_select_db("comments"); $name = mysql_real_escape_string($_POST['name']); $postID = mysql_real_escape_string($_POST['postId']); if(!is_numeric($postID)) exit(); $email = mysql_real_escape_string($_POST['email']); $comment = strip_tags(mysql_real_escape_string($_POST['comment']), ''); $date = mysql_real_escape_string($_POST['date']); if($email == '' || $comment = '' || $date = '') exit(); $query = "INSERT INTO comments (PostID,Name,Email,Text,Date) VALUES($postID, '$name', '$email', '$comment', '$date')"; mysql_query($query) or die(mysql_error()); mysql_close(); echo " window.location = \"snippet.php?id=$postID\"; ";
答案 0 :(得分:3)
您正在使用$comment
$date
和=
if($email == '' || $comment = '' || $date = '')
exit();
// Should use `==` for all three:
if($email == '' || $comment == '' || $date == '')
exit();
答案 1 :(得分:0)
您正在尝试将$comment
和$date
与无效字符进行比较
请替换此行:
if($email == '' || $comment = '' || $date = '')
与
if($email == '' || $comment = '' || $date == '')