Having trouble passing value to select statement

ohsnyder
03:31:12
need correct syntax to pass selected drop down value to a search statement.

Drop Down page code & URL: http://aabees.org/clubs_state.php

<?php

include("menu.php");

echo "<form name='clubs' action='clubs.php' method='post'>

<table align=center>

<th colspan=2><h2>Select a State to see the Bee Clubs </h2></th>

<tr align=center><td>

<select name='state'>
<option value='' selected>Select a State </option>
<option value='state'>Alabama</option>
<option value='state'>Alaska</option>
</select>

</td></tr>

<tr align=center><td><input type='submit' value='See the List' /></td></tr>

</table>";

?>

Process page code & URL: http://aabees.org/clubs.php

<?php

include("menu.php");

$con = mysql_connect("localhost","******","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mdwvo_aaba", $con);


$result = mysql_query("SELECT * FROM clubs WHERE (problem area) deleted ='No' ORDER BY level, club");

$row = mysql_fetch_array($result);

Print "<table align=center width=80%";
Print "<tr><th align=center><h2>Listing of Bee Clubs in ".$row['state'] . " </h2></th>";
Print "<table align=center width=80% cellpadding=3>";
Print "<tr><th align=left>ID</th><th align=left>Club Name</th><th align=left>Web Site</th></tr>";


$result = mysql_query("SELECT * FROM clubs WHERE deleted ='No' ORDER BY level, club");

while($row = mysql_fetch_array($result))
{


Print
"<tr><td>".$row['id'] . "</td>
<td>".$row['club'] . "</td>
<td align=left>".$row['url'] . " </td>
</td></tr>";
}
Print "</table>";

mysql_close($con);
?>


smo1234
04-01-2012
Inside your selection all the values are same and equal to state. You should have different values for different states.
Then you need to ensure that at clubs.php page you are getting the selected data. You have to collect them like this

$state=$_POST['state'];

Now use SQL where clause and use the variable to get the data of that particular state.

You must also ensure that your database connection is correct and your sql syntax is fine.

Please don't expose your database login userid and password here.
Please Login to post your reply or start a new topic