Reputation: 59
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
}
Upvotes: 0
Views: 904
Reputation: 11984
This code will work. i had removed the semicolon(;) before 'or die' which caused the 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
}
Upvotes: 0
Reputation: 64526
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.
Upvotes: 14
Reputation: 12655
you can't begin the line with "or" In line 118 you end with ";"
$count = mysql_num_rows($result) or die mysql_error();
But it would be better to to the error checking after result:
if(!$result) {
die mysql_error();
}
Upvotes: 0
Reputation: 3289
Please remove semicolon and add () to die in order to show it is errors & then die
$count=mysql_num_rows($result) or die(mysql_error()); //line 119
Upvotes: 0
Reputation: 167172
$count=mysql_num_rows($result);
------------------------------^
or die mysql_error();//line 119
$count=mysql_num_rows($result) or die mysql_error();
It terminates!!!
Do not use mysql_*
functions as they are deprecated. Use mysqli or PDO instead.
Upvotes: 1
Reputation: 176
Try changing this:
$count=mysql_num_rows($result);
or die mysql_error();//line 119
To this:
$count=mysql_num_rows($result) or die mysql_error();//line 119
Upvotes: 0