variable problem...

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

Post Reply
dmakris
Forum Newbie
Posts: 11
Joined: Tue Jun 03, 2003 7:58 am
Location: Greece

variable problem...

Post by dmakris »

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> </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

and

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]
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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...
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Code: Select all

&lt;?php
if (isset($_POST&#1111;'check']))
{    
     $Dest =  "Location: http://www." . $_POST&#1111;'Selected'];
     header($Dest);
     exit;
}
else
{
?&gt;php
     &lt;html&gt;
     &lt;body onload=setfocus() bgcolor="#FFEECE"&gt;
     &lt;table cellpadding="20" align="center"&gt;
     &lt;form action="check.php" method="post" name="form" id="form"&gt;
     &lt;table&gt;
     &lt;tr&gt;&lt;select name="check" onChange="submit()"&gt;
     &lt;option value="check.php" selected&gt;select&lt;/option&gt;
     &lt;option value="mysite1.org"&gt;option1&lt;/option&gt;
     &lt;option value="mysite2.org"&gt;option2&lt;/option&gt;
     &lt;option value="mysite3.org"&gt;option3&lt;/option&gt;
     &lt;/select&gt;&lt;/tr&gt;
     &lt;/table&gt;
     &lt;/form&gt;
     &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
     &lt;/html&gt;
&lt;?php
}
?&gt;php
Edit: i added the exit; to prevent the html from being executed if the $_POST is passed.
:oops:
Last edited by Bill H on Thu Jan 06, 2005 11:14 am, edited 4 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might want to check your bits there, bill ;)
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

"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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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.
Post Reply