Forum Moderators: coopster

Message Too Old, No Replies

PHP Dynamic select menu

         

dave1236

3:21 am on Jun 3, 2007 (gmt 0)

10+ Year Member



I am trying to replace a basic html based <option value> menu with a php based menu.

I have successfully been able to build my list, at least getting the option values to appear in a drop down list.

The issue I have is getting my menu to redirect my users based on their selection. the sample I have used simply echoes the selection.

Any thoughts on how to redirect my users?

Here is what I currently use...

<select id="list">
<OPTION value="#"> Select a Store
<OPTION value="store100.php" >Store100.com
</SELECT>

On selection...they were redirected using the following...
<input type="button" value="Go!" onclick="location.href=document.getElementById('list').value" />

As some change periodically, as I add new/delete old, I want this list to be dynamically generated.

Here is my php code:

$query = "SELECT * FROM Stores WHERE status = 'active' ORDER BY storename";
$result = mysql_query($query)
or die ("Couldn't execute query-come on now!");

/* create form containing selection list */
echo "<form action='processform.php' method='POST'>
<select name='storename'>\n";

while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<option value='$storename'>$storename\n";
}
echo "</select>\n";
echo "<input type='submit' value='Select Type of Pet'>
</form>\n";
?>
</body></html>

I think my issue is in processform.php which does the following:

<?php
/* Script name: processform.php
* Description: Script displays all the information passed
* from a form.
*/
echo "<html>
<head><title>Customer Address</title></head>
<body>";
foreach ($_POST as $field => $value)
{
echo "$field = $value<br>";
}
?>
</body></html>

Any ideas on how to modify process form to redirect to the url designated?

Thanks!

Habtom

4:59 am on Jun 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



//The issue I have is getting my menu to redirect my users based on their selection.

shouldn't this do it:
header("Location : selecteddest.php");

Habtom

dave1236

1:57 am on Jun 4, 2007 (gmt 0)

10+ Year Member



Habtom:

Thanks! I was able to verify your solution is what I need to implement - however, I cannot seem to get the file to recognize the database field as my destination...

here is what I got (this works!)

header("Location: destination");

but here is what I want:

header("Location: $program");

$program represents the destination page that is dynamic

Thanks!