PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dmakris
Forum Newbie
Posts: 11 Joined: Tue Jun 03, 2003 7:58 am
Location: Greece
Post
by dmakris » Wed Jan 05, 2005 7:26 am
I have created two pages. The first one has an option menu and the second one has a header function so I can redirect the user depending the option he made in the first page. Do u know how can i use the option variable of the first page to the second one?
first page
Code: Select all
<html>
<body onload=setfocus() bgcolor="#FFEECE">
<table cellpadding="20" align="center">
<form action="check.php" method="post" name="form" id="form">
<table>
<tr><select name="check" onChange="submit()">
<option value="0" selected>&nbsp;</option>
<option value="1">option1</option>
<option value="2">option2</option>
<option value="3">option3</option>
</select></tr>
</table>
</form>
</td></tr></table>
</html>
second page
Code: Select all
<?php
if (&check=1) {
header("Location: http://www.mysite1.org/");
else
{
header("Location: http://www.mysite2.org/");
}
?>
feyd | Help us, help you. Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Wed Jan 05, 2005 7:55 am
The Code for second page will be :
Code: Select all
<?php
if($_POST["check"]==1) //if user chooses option 1
header("Location: http://www.mysite1.org/"); //go somewhere
else if($_POST["check"]==2) //if user chooses option 2
header("Location: http://www.mysite2.org/"); //go somewhere else
else //if user chooses option 3
header("Location: http://www.mysite3.org/"); //go third where...
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 05, 2005 9:39 am
personally, I'd use a switch:
Code: Select all
switch($_POST['check'])
{
case 1:
$url = 'http://www.site1.com';
break;
case 2:
$url = 'http://www.site2.com';
break;
case 3:
$url = 'http://www.site3.com';
break;
default:
$url = 'http://www.site.com'; // value of zero or any other value that didn't get caught.
break;
}
header('Location: ' . $url);
Hibba
Forum Commoner
Posts: 58 Joined: Fri Oct 29, 2004 11:37 pm
Post
by Hibba » Wed Jan 05, 2005 10:01 pm
Why not make it all included? Just have everything in one php file, have the form submit to itself and pass the variable that way.
One less file and everything is together.
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Thu Jan 06, 2005 8:43 am
Code: Select all
<?php
if (isset($_POSTї'check']))
{
$Dest = "Location: http://www." . $_POSTї'Selected'];
header($Dest);
exit;
}
else
{
?>php
<html>
<body onload=setfocus() bgcolor="#FFEECE">
<table cellpadding="20" align="center">
<form action="check.php" method="post" name="form" id="form">
<table>
<tr><select name="check" onChange="submit()">
<option value="check.php" selected>select</option>
<option value="mysite1.org">option1</option>
<option value="mysite2.org">option2</option>
<option value="mysite3.org">option3</option>
</select></tr>
</table>
</form>
</td></tr></table>
</html>
<?php
}
?>php
Edit: i added the exit; to prevent the html from being executed if the $_POST is passed.
Last edited by
Bill H on Thu Jan 06, 2005 11:14 am, edited 4 times in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 06, 2005 8:45 am
might want to check your bits there, bill
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Thu Jan 06, 2005 8:52 am
"bits?" Is my edit what you were referring to feyd.?
I have Parkinson's -- my fingers stutter on the keyboard.
I tried the php tags but they didn't work, so I used code tags.
The "php logic" tag is cool, how is that applied?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 06, 2005 8:56 am
yep, that's what I was talking about, more or less.
no worries.
the labeling is done through this:
Code: Select all
read through the posting code thread for more details and features available through the tag.