如果表单值等于特定的则死亡

时间:2011-01-30 17:39:24

标签: php mysql

在使用$_POST函数将数据输入数据库之前,我想检查字段的名称。如果comment_author_name等于特定名称,我想退出/死/杀该函数。

例如,如果评论作者的名字在HTML表单上是John,我希望PHP函数死掉,这样数据就不会输入到数据库中。

以下代码无效。我错过了什么?有更好的方法吗?

<?php
    $val1 = "John";
    if (($row->comment_author_name) == ($val1))
        {
    die("You are not allowed to post!");
        }
?>

1 个答案:

答案 0 :(得分:1)

你可以这样做:

if ($_POST['comment_author_name'] == 'John'){
  die("You are not allowed to post!");
}
相关问题