首页 文章

PHP没有处理某些表单字段

提问于
浏览
2

我最近创建了一个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\";
        
    ";

1 回答

  • 3

    您正在使用 = 将空字符串分配给 $comment$date

    if($email == '' || $comment = '' || $date = '')
        exit();
    
    // Should use `==` for all three:
    if($email == '' || $comment == '' || $date == '')
        exit();
    

相关问题