1

Possible Duplicate:
PHP (MySQL) error : “Warning: mysql_num_rows() expects parameter 1 to be resource”

I've been getting an annoying error with my code..

48. mysql_select_db("serverip_gamepwn", $con);
49. $username_session = $_COOKIE['GamePwN_LOL_Username'];
50. $username_session = mysql_real_escape_string($username_session);
51. $result = mysql_query("SELECT * FROM orders WHERE username='$username_session'");
52. $count = mysql_num_rows($result);
53. if($count != 1){

The error code is:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/serverip/public_html/gamepwn.net/lol/status.php on line 52
Community
  • 1
  • 1
  • There doesn't appear to be any syntax problem with your query (unless the table or column don't exist). You probably had an error in your `mysql_connect()` call or no permission to use the database selected. – Michael Berkowski Jan 28 '12 at 13:18

3 Answers3

1

Replace

$count = mysql_num_rows($result);

with

$count = mysql_num_rows($result) or die(mysql_error());

and see what it says

Jared
  • 406
  • 4
  • 14
  • It's more normal to add the `or die()` statement on the same line as `mysql_query`, isn't it? I'm not sure your suggestion will have the intended behaviour. – grahamparks Jan 28 '12 at 14:35
0

$result is no valid Resultset, probably your query contains a syntax error and therefore the result became false. You can fetch the error-message via mysql_error()

TimWolla
  • 30,523
  • 8
  • 64
  • 89
0
//use this way it will workout 

$result = mysql_query("SELECT * FROM orders WHERE username= '".$username_session."'");

$count = mysql_num_rows($result);

//now the count will be one

if($count != 1){
}else{
}
Sam Arul Raj T
  • 1,712
  • 16
  • 21