Query not returning results with isset

Not sure what I am doing wrong. I’m learning :wink:

I expect the below code to find one business by id and see if the businesses zip code is found in Florida_Zips column and display the resulting image. It should find one entry, but finds nothing and no errors are being displayed :

URL is called like this: test.php?id=1234&Business_Zip=56789

Thank you very much to anyone kind enough to help me!

<?php
if (isset($_GET['id'], $_GET['Business_Zip']))
{
$con=mysqli_connect("localhost","*****","*****","*****");
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id = ($_GET['id']);
$Florida_Zips = ($_GET['Florida_Zips']);
$Business_Zip = ($_GET['Business_Zip']);

$result = mysqli_query($con,"SELECT * FROM DATA WHERE '$Business_Zip' LIKE '$Florida_Zips' AND id = " . $_GET['id']);
while($row = mysqli_fetch_array($result))
{
echo '<br><img src="images/Florida.png" style="padding-bottom:8px;">';
}
mysqli_close($con);
}
?>

Not sure I understand your intent, but a couple of things:

  1. Your query assumes $Business_Zip is a column name in the DATA table; is that what you mean? If so, it shouldn’t be a variable - the column name doesn’t change;
  2. Check the LIKE statement, you may need to qualify that. If you’re looking for an exact match, use WHERE field_name = $value;
  3. If you are getting an answer in the $row variable, you aren’t using it anywhere, you’re just echoing an image in your while loop.
    As a suggestion, try running your query directly in a database client with test variables and make sure it works properly there first.
Sponsor our Newsletter | Privacy Policy | Terms of Service