Forum Moderators: coopster
<form name=\"state_search\" action=\"search/state_search.php\" method=\"post\">
<p>Please choose your state: </p>
<SELECT name=\"state_search\" size=\"1\" HEIGHT = \"22\" WIDTH = \"50\">
<OPTION value=\"-1\">-</option>
<OPTION value=\"FL\">FL</option>
</SELECT>
<input type=\"submit\" />
------------------------------------------
Here is the state_search.php
as follows:
<?
if ($search)
{
mysql_connect() or die ("Problem connecting to Database");
$query = "select * from search WHERE state_abbreviation='$search'";
$result = mysql_db_query("state_search", $query);
if ($result)
{
echo "Here are the results:<br><br>";
while ($r = mysql_fetch_array($result)) { // Begin while
$ts = $r["TimeStamp"];
$state_abbreviation = $r["state_abbreviation"];
$name = $r["name"];
$city = $r["city"];
$zip = $r["zip_code"];
echo "<tr>
<td>$ts</td>
<td>$name</td>
<td>state_abbreviation</td>
<td>$city</td></tr>
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$zip</td>
</tr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}
?>
Mysql_connect contains no arguments so it will only be able to attempt a default connection.
Also mysql_db_query is deprecated - use mysql_select_db .
Basic connect script here [uk.php.net...]
<form name=\"state_search\" action=\"search/state_search.php\" method=\"post\">
<SELECT name=\"state_search\" size=\"1\" HEIGHT = \"22\" WIDTH = \"50\">
your form and select have same name which is bad practice though it has nothing to do with your problem.
if ($search){
$search = $_post['state_search'];
if(!empty($search)){
//connect to database
mysql_connect("host", "user", "password");
mysql_select_db("database");
$sql = "SELECT * FROM table WHERE state_abbreviation='$search'";
$result = mysql_query($sql);
if($result){
while($r = mysql_fetch_array($result){
//do some stuff here
}
}
}