-5

When i run the following query to check username and password, it throws an error.

PHP

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' AND password='$mypassword'";
$result=mysql_query($sql);

if($result === false) {
var_dump(mysql_error());}
else {
print_r(mysql_num_rows($amn));
}

Error

[Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given]

Result of var_dump

[You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update WHERE username='admin' AND password='123456' at line 1' (length=199)]

Brian Kerr
  • 413
  • 3
  • 14
Affan Malik
  • 162
  • 2
  • 13

1 Answers1

1

update is a reserved word in mysql - http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html.
It would be best to rename your table name. At the very least escape your table name with backticks - ``.

$sql="SELECT * FROM `$tbl_name` WHERE username='$myusername' AND password='$mypassword'";

which parses to -

SELECT * FROM `update` WHERE username='admin' AND password='123456'
Sean
  • 12,439
  • 3
  • 27
  • 46