mysql_num_rows()期望参数1是资源,第31行/home/domain/public_html/config.php中给出的布尔值[关闭]

I know that this is very frequently problem. I have two hosting A and B and one mysql base. On hosting A site works but the same web page (I copy file from A to B) on hosting B doesn't work perfectly. Host, login and password to date base is ok because i see news etc. But when i try login to my admin panel i see:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/dmcmetal/domains/mydomain.com/public_html/config.php on line 31

I add to my config.php file mysql_error(); and now i see:

 Something is wrong in your syntax obok '=='1' LIMIT 1' w linii 1

Here is the part of config.php file:

function get_user_data($id=-1) {
if($id==-1) {
    $id=$_SESSION['id'];
}
$result=  mysql_query("SELECT * FROM `users` WHERE `id`=='{$id}' LIMIT 1");
if($result==FALSE)
    die(mysql_error());
if(mysql_num_rows($result)==0) { // 31 line
    return false;
}
return mysql_fetch_assoc($result);

}

Can anyone have idea why it works on hosting A and doesn't work on hosting B ?

There is a syntax error in your query, you are using double equals when mysql syntax requires a single one. This is causing the error since there is no number of rows. So please change to

$result=  mysql_query("SELECT * FROM `users` WHERE `id` = '{$id}' LIMIT 1");

Then I would like you to remember that mysql_* functions are deprecated so i would advise you to switch to mysqli or PDO

id ='{id}'

instead of

id =='{id}'

What you're doing is checking the equality of id which is improper syntax as id is a column name.

The error you are getting is because your query is not syntactically correct .. and so mysql_query() is retruring false ..

So parameter that is being transeferred to mysql_num_rows() is false

please change

$result=  mysql_query("SELECT * FROM `users` WHERE `id` == '{$id}' LIMIT 1");

to

$result=  mysql_query("SELECT * FROM `users` WHERE `id` = '{$id}' LIMIT 1");

NOTE : I suggest you to switch to mysqli_* or PDO as mysql_ are depreciated

see for PDO and mysqli

you can also have look at prepared statements.