php mysql variable arguments in query.
Hi,
I have a small mysql db containing some contact information. It works fine and I can add new records to it using a html/php frontend page.
But when I try to retrieve specific records using the 'name' field, I get some strange results:
This is some of the code in the target (from the form) script:
case "shuser":
$query = "select * from contact where surname = '$p1'";
$result = mysql_query($query, $link);
if (!$result) {
die('Error while showing contact: ' . mysql_error());
}
echo "<html><head><title>contact info: $p1</title></head><body>";
echo "<table width=\"90%\" border=\"1\" align=\"center\"><tr><td>name</td><td>surname</td><td>phone</td><td>mobile</td><
/tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td></tr>";
}
echo "</table><br/><br/><div align=\"center\"><a href=\"contactDB.php\">return to the homepage</a></div></body></html>";
This query: $query = "select * from contact where surname = '$p1'"; looks ok to me but not to my pc. I can execute it but it don't show anything in the table. I have to use '$p1' because I get an error if I omit the '
In mysql itself, I can execute the query without any problem but then I don't use any variables. Even when I change the variable for a fixed value, I get no results.
Any ideas?
Thanks,
Lieven
|