2011-01-30 160 views
0

在我的數據使用$_POST函數輸入到數據庫之前,我想檢查一個字段的名稱。如果comment_author_name等於一個特定的名稱,我想退出/死亡/殺死該函數。如果表單值等於一個特定值,然後死

例如,如果評論作者的姓名在HTML表單上是John,我希望PHP函數死掉,以免數據輸入到數據庫中。

以下代碼無法正常工作。我錯過了什麼?有一個更好的方法嗎??

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

哪裏是`$ row`來自哪裏?你確定你不是指`$ _POST ['comment_author_name']`? – middus 2011-01-30 17:41:20

回答

1

你可以這樣做:

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