doucheng5209 2013-01-04 14:48
浏览 102
已采纳

mysql_num_rows()错误

I seem to be having a rough time with this snippet of code, Which i dont understand because on my home server this works 100% perfect. basically this script takes the users ip and stores it into a mysql table. every time a user posts it checks the table to see if the ip has already posted. when i run mysql_error() on num_rows which apears to be the problem, i get:

Parse error: syntax error, unexpected T_LOGICAL_OR on line 119

Any ideas?

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
}
  • 写回答

7条回答 默认 最新

  • doucong3048 2013-01-04 14:49
    关注

    Remove the semicolon because that terminates the statement and the or die is treated as a new statement, causing the error:

    $count=mysql_num_rows($result) or die(mysql_error());
                             //   ^ no semicolon
    

    You also need parenthesis around the die() call.

    Side note: or die(mysql_error()) is not considered good practice because it's difficult to maintain between development and production environments. or trigger_error(mysql_error()) would be better - this writes to your error log. Also consider upgrading to PDO or MySQLi because this MySQL library is deprecated and discouraged.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制