Web Hosting Talk







View Full Version : PHP Script to Redirect to Different Pages Base on Select in Menu


texasweb
02-06-2002, 01:59 AM
I have an PHP application. I have coded everything I need except for this one thing.

I have a menu that is dynamically built reading from 4 MYSQL tables. I want to send the user to different html pages depending on 1 of 4 selections that was selected.

I feel really dumb asking this, but can someone give me the code or direct me in the right direction?

Thanks

Lats
02-06-2002, 02:46 AM
A good place to go lookin' is...

http://www.hotscripts.com/PHP/


Lats...

mkaufman
02-06-2002, 11:50 AM
Just name the drop down menu something like "dropdown" and then name each value "section1, section2, section3, section4" etc... and do:


<?php
if($dropdown == section1) {
header("Location: section1.php");
}
// etc....
?>


Make sure that file is on a new page, since it uses header functions.

Ahmad
02-06-2002, 12:22 PM
As mkaufman said ..

But for me, I would save my server a hit using javascript.

madsere
02-06-2002, 01:40 PM
I think header() will redirect the page, but you lose any form variables set at this point, i.e. if a user has logged in, once you've used header() to redirect him to another page the login name has been lost. I suppose you can use session variables but isn't there an easier way?

Ahmad, how about a Javascript example ?

texasweb
02-06-2002, 06:01 PM
The script using the header function worked great! My hands off to mkaufman. I didn't have any variables that I passed that I cared about, so it worked excellent as is.

I would be interested in the javascript example also, just for grins.

Again, many thanks.