I am fairly new to PHP and MYSQL and was having a few problems getting a database search script to work. The data is input through an HTML form with an input field and drop down box to narrow results. This code will work for searching one table but as soon as I try and search multiple tables it returns 0 results. When using the drop down box PHP or MYSQL seems to only look at the table fields where the data is rather then the table as a whole. Those fields are name, address, website, telephone, location. Below the fields for the drop down are setup to how I would want them to work, as they are the table names : soda, chocolate, wine, cigars etc...If you can please help I'd appreciate it.... Heres the code
// HTML
...
<select name="metode" class="category_select">
<option value="name">Beer</option>
<option value="chocolate">Chocolate</option>
<option value="cigars">Cigars</option>
<option value="glass">Glass</option>
<option value="wine">Wine</option>
</select><br><br>
...
// PHP stuff
<? $hostname = "localhost"; // The Thinkhost DB server.
$username = "**"; // The username you created for this database.
$password = "**"; // The password you created for the username.
$usertable = "soda"; // The name of the table you made.
$dbName = "**"; // This is the name of the database you made.
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
//error message (not found message)begins
$XX = "No Record Found, to search again please close this window";
//query details table begins
$query = mysql_query("SELECT name, website FROM $usertable WHERE $metode LIKE '%$search%' "); // problem AREA
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["soda"];
$variable2=$row["chocolate"];
$variable3=$row["cigars"];
$variable4=$row["glass"];
$variable5=$row["wine"];
//table layout for results
echo " <b>", $variable1.": <b> <br>";
echo " ", $variable2.": <b> <br>";
echo " ", $variable3.": <b> <br>";
echo " ", $variable4.": <b> <br>";
echo " ", $variable5.": <b> <br>";
}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>