[英]mysql_num_rows() error
我似乎對這段代碼很不滿意,我不明白,因為在我的家庭服務器上,這是100%完美的。 基本上,此腳本使用用戶ip並將其存儲到mysql表中。 每次用戶發布時,它都會檢查表以查看IP是否已經發布。 當我在num_rows上運行mysql_error()時,這是問題所在,我得到:
Parse error: syntax error, unexpected T_LOGICAL_OR on line 119
有任何想法嗎?
的PHP:
$poster_ip=$_SERVER['REMOTE_ADDR'];//Posters ip
//check for ip double posting
//selecet ip from table
$sql="SELECT * FROM $tbl_name WHERE ip='$poster_ip'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
or die mysql_error();//line 119
//if result matche posterip, table row must be 1
if($count==1){
//ip taken
echo "This IP has already submited a post. You may not submit another.";
exit();
//else script continues
}
嘗試更改此:
$count=mysql_num_rows($result);
or die mysql_error();//line 119
對此:
$count=mysql_num_rows($result) or die mysql_error();//line 119
請刪除分號並添加()到死,以顯示它是錯誤然后死
$count=mysql_num_rows($result) or die(mysql_error()); //line 119
您不能以“或”開始該行。在第118行中,您必須以“;”結束
$count = mysql_num_rows($result) or die mysql_error();
但是最好對結果后的錯誤進行檢查:
if(!$result) {
die mysql_error();
}
此代碼將起作用。 我已經刪除了導致錯誤的分號(;),否則導致錯誤..
$poster_ip=$_SERVER['REMOTE_ADDR'];//Posters ip
//check for ip double posting
//selecet ip from table
$sql="SELECT * FROM $tbl_name WHERE ip='$poster_ip'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result) or die mysql_error();//line 119
//if result matche posterip, table row must be 1
if($count==1){
//ip taken
echo "This IP has already submited a post. You may not submit another.";
exit();
//else script continues
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.