Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

PHP dropdown menu

I'm looking for a PHP dropdown menu that changes pages when an option is selected, such as the Ford option changes to the Mustang page. Is the PHP code better than using Java ? I"m looking for security in he code also. I will be reading the values from a MySQL database which is already setup.

Thanks,
Michael
0
mhoggatt1
Asked:
mhoggatt1
  • 3
  • 2
1 Solution
 
MasonWolfCommented:
Ok, try this: (Place the php code at the very top of your script, even before an empty line or an html type declaration)

<?php
    if(isset($_POST['page']))
    {
          header('Location: '.$_POST['page']);
          exit;
    }
?>

Somewhere in your body write:

<form action='' method='post'>
<select name='page' onchange='this.form.submit()'>
<option>Select a make:</option>
<option value='Ford/mustang.html' onclick='this.form.submit()'>Ford Mustang</option>
<option value='Ford/F150.html onclick='this.form.submit()''>Ford F-150</option>
<option value='Dodge/viper.html onclick='this.form.submit()'>Dodge Viper</option>
...(add as many additional options as you like)
</select>
</form>
0
 
mhoggatt1Author Commented:
Thanks for the reply. Let me see if I can integrate it with my DB and I'll get back to you tomorrow.

Michael
0
 
mhoggatt1Author Commented:
Here is my code with the database added. How do I make the options equal to the values in my DB ?
I wan't action_name to appear in the menu which changes to the page when selected.
I am not actually using cars for my code but for purposes of this question action_name would be Ford and directory_link would be Mustang.

Thanks,
Michael
0
 
MasonWolfCommented:
Please post your code and I will take a look at it.
0
 
mhoggatt1Author Commented:
Thanks for all your help.
Michael
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now