MYSQL_NUM_ROWS期望参数1是资源

时间:2012-01-28 13:10:55

标签: php mysql

  

可能重复:
  PHP (MySQL) error : “Warning: mysql_num_rows() expects parameter 1 to be resource”

我的代码出现了令人讨厌的错误..

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){

错误代码是:

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

3 个答案:

答案 0 :(得分:1)

替换

$count = mysql_num_rows($result);

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

看看它的内容

答案 1 :(得分:0)

$result无效Resultset,可能您的查询包含语法错误,因此结果变为false。您可以通过mysql_error()

获取错误消息

答案 2 :(得分: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{
}