I have a small script that is supposed to take a variable from a form, search 5 tables of a database, and forward the results on to another page to either show an error, or show the data from the proper table.
Here's the code...
<?
include("db_connect_mls.inc.php");
// $table_names is an array set up in db_connect_mls.inc.php
foreach ($table_names as $table)
{
$query = "SELECT * FROM $table WHERE LISTING_ID='$LISTING_ID'";
$result = mysql_query($query)
or die ("Unable to execute query");
while ($row = mysql_fetch_array($result))
{
header("Location: ../listing_detail.php?table=$table&LISTING_ID=$LISTING_ID");
}
}
header("Location: ../listing_detail.php");
?>
The table names are stored in an array called table_names.
The problem I'm seeing is that whether LISTING_ID is found or not the header line outside the loop is the one that gets triggered. If I comment out the bottom header line and the LISTING_ID is found, it works great.
Am I just an idiot?
TIA