I am having issues with the code that I created. I want to run a query based on a drop down options. Here is the code that I have created.
Drop Down Page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>DB Connection</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="locator_script.php">
<p>State:
<select name="state">
<option value="KS">KS</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Search">
</p>
</form>
</body>
</html>
the script that the above code is posting to.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Locations</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?
//Database Connection
include "db_connection.php";
//Query
$sql = "select * from locations where state = $state";
//execute SQL query and get result
$sql_result = mysql_query($sql,$connection) or die ("Couldn't execute query.");
//
$row = mysql_fetch_array ($sql_result);
//start results formatting
echo "<TABLE BORDER=1>";
echo "<TR>
<TH>State</TH>
<TH>City</TH>
<TH>Zip</TH>
<TH>Zone</TH>
<TH>Country</TH>
<TH>Name</TH>
<TH>Link</TH>
</TR>";
//format results by row
while ($row = mysql_fetch_array($sql_results)) {
$state = $row["STATE"];
$city = $row["CITY"];
$zip = $row["ZIP"];
$zone = $row["ZONE"];
$country = $row["COUNTRY"];
$name = $row["NAME"];
$link = $row["LINK"];
echo "<TR>
<TD>State</TD>
<TD>City</TD>
<TD>Zip</TD>
<TD>Zone</TD>
<TD>Country</TD>
<TD>Name</TD>
<TD>Link</TD>
</TR>";
}
echo "</TABLE>";
//free resources and close connection
mysql_free_result($sql_results);
mysql_close($connection);
?>
<body>
</body>
</html>
when I click submit on the drop down page it take me to the result page with an "Cannot Execute Query" I am stumped as to what I have done wrong. Any help would be great.
Thanks.