• I need help with a query in mysql.
    2 replies, posted
Okey, my project is holding up because of this error. [PHP]$check = mysql_query("SELECT * FROM pim WHERE recieveremail='$_SESSION[user_email]' AND read='0' ");[/PHP] Thats returning a boolean() But what i wanna return is the count, so for that i used this code [PHP] $count = mysql_num_rows($query); if ($count > 0){ return $count; }else{ return 0; } [/PHP] Then im getting this error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\backend\classes.php on line 57 bool(false) Thanks!
[php] $check = mysql_query("SELECT * FROM pim WHERE recieveremail='$_SESSION[user_email]' AND read='0' "); $count = mysql_num_rows($check); [/php] Read the [url=http://www.php.net/manual/en/function.mysql-num-rows.php]documentation[/url]. Also, stop using mysql_query(): [img]http://i.imgur.com/go5Ie.png[/img]
[QUOTE=linslusa;38233054][PHP]$check = mysql_query("SELECT * FROM pim WHERE recieveremail='$_SESSION[user_email]' AND read='0' ");[/PHP][/QUOTE] What stands out to me is your variable... [CODE]$_SESSION[user_email][/CODE] ...without quotes; it could be that query string, try something along this line: [PHP]$check=mysql_query("SELECT * FROM pim WHERE recieveremail='".$_SESSION["user_email"]."' AND read='0'");[/PHP] [editline]29th October 2012[/editline] If the [I]$_SESSION["user_email"][/I] is submitted on demand then be sure to sanitize that bugger. [editline]29th October 2012[/editline] [PHP] $query=mysql_query("SELECT * FROM pim WHERE recieveremail='".$_SESSION["user_email"]."' AND read='0'"); if(!$query){ exit("Query error."); } // Process [/PHP]
Sorry, you need to Log In to post a reply to this thread.