Reputation: 483
Please help me with how can I retrieve data from mysql having a variable in my sql query.. my php code is
$status=$_GET['status'];
$query="SELECT * FROM students WHERE status='$status' ";
When I run the query mysql generates
unknown column 'Lead'
where Lead is the value of $status. I tried it with \'$status\' , '{$status}' but same error.. Please help me I'm working on it since yesterday but found no solution. I tried mysql_real_escape_string() but same error.. may be I was using it with wrong syntax.
$query="SELECT * FROM students WHERE status=".mysql_real_escape_string($status);
Thanks in advance....
Upvotes: 0
Views: 1170
Reputation: 76508
$status=$_GET['status'];
$query="SELECT * FROM students WHERE status='".$status."'";
and escaping is a good idea, but I think mysql_escape_string is deprecated and its usage is discouraged, you should always use mysql_real_escape_string
.
Upvotes: 1
Reputation: 14853
I'm afraid 'status' is a reserved word for sql: see http://drupal.org/node/141051
Try:
$status = mysql_real_escape_string($status)
$query = "SELECT * FROM `students` WHERE `status` = '$status'";
Upvotes: 0