PHP没有处理某些表单字段

时间:2011-09-10 20:02:41

标签: php mysql comments commenting

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

2 个答案:

答案 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 == '')