php - $_GET method not works while passing a string via URL -
this question has answer here:
please help, $_get
method not works while passing string via url
i got following error
warning: mysql_fetch_array() expects parameter 1 resource, boolean given.
when access id
via url $_get
method works.
at same time query doesn't work while passing string (ex: bihar) via method.
how solve issue?
<?php include('config.php'); $qry = "select districtname pincode_data statename =" . $_get['st']; // here issue.. not works me. // $qry = "select districtname pincode_data statename =" . $_get['id']; // query works // $qry = "select districtname pincode_data statename = 'bihar'"; // query works $result = mysql_query($qry); while($row = mysql_fetch_array($result)) { echo "<li><a href='districtview.php?dist=".$row['districtname']."'> ".$row['districtname']."</a></li>"; } mysql_close(); ?>
i guess statename
char
type, have make single qoutes arraound yout value;
$qry = "select districtname pincode_data statename ='" . $_get['st']."'";
if don't syntax error in mysql , thats why error in php.
the query:
$qry = "select districtname pincode_data statename =" . $_get['id'];
works because id
is numerical column , there no need single quotes.
but shouldn't use deprecated mysql_*
api. use mysqli_*
or pdo
prepared statements.
Comments
Post a Comment