Hi there. I am pretty new to PHP and finding it pretty cool..
Having problem with the following code..
Have the Select working fine on opening the page, but the ONSUBMIT is not printing the desired results.
Copied the code from:
http://p2p.wrox.com/topic.asp?TOPIC_ID=17383
Code:
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
//http://p2p.wrox.com/topic.asp?TOPIC_ID=17383
$city = null; //declare vars
$conn = mysql_connect ("localhost","login","password");
$db = mysql_select_db('database',$conn);
if(isset($_GET["city"]) && is_numeric($_GET["city"]))
{
$city = $_GET["city"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<select name="city" onChange="autoSubmit();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN REGION, COUNTRY
$sql = "SELECT DISTINCT city FROM lodges";
$cityname = mysql_query($sql,$conn);
while($row = mysql_fetch_array($cityname))
{
echo ("<option value=\"$row[city]\" ".($city == $row["city"] ? " selected" : "").">$row[city]</option>");
}
?>
</select>
<?php
if($city != null)
{
//POPULATE DROP DOWN MENU WITH CITIES FROM A GIVEN REGION, COUNTRY, STATE
$sql = "SELECT id, secretary FROM lodges WHERE city = $city ";
$secretaries = mysql_query($sql,$conn);
while($row = mysql_fetch_array($secretaries))
{
echo $row[secretary];
}
?>
</form>
</body>
</html>
The dropdown works great, but I see no restults onchange..
Thanks,
Kent