php - Why mysql_fetch_assoc() returns null? -Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in -


i'm new in php , struggle problem.here code:

<?php   mysql_connect("127.0.0.1","root","root");  mysql_select_db("gps");  $login=$_get["login"];  $user_name=$_get["user_name"];  $password=$_get["password"];  if ($login)  {     $sql=mysql_query("select * users user_name='".$user_name."' ,  password='".$password."'  limit 1");     $output[]=mysql_fetch_assoc($sql);  }  else  {     $sql=mysql_query("select name,device_id,lat,lon,user_name  devices,users limit 100");     while($row=mysql_fetch_assoc($sql))      {          $output[]=$row;     }  }  print(json_encode($output));  mysql_close();  ?> 

then try in localhost way: htt.../getproducts-2.php?login=true&user_name=jane&password=1234

then got error:warning: mysql_fetch_assoc() expects parameter 1 resource, boolean given in c:\wamp\www\getproducts-2.php on line 13

what should do? what's wrong code?

i solved problem reorganizing code according purposes there aren't erors or warnings. thank advices.

probably query fails because of field or table name misspelling. if query fails mysql returns false. that's why error message boolean.

also mysql_query deprecated: see alternatives here


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -