Page 1 of 1

variable problem...

Posted: Wed Jan 05, 2005 7:26 am
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]

Posted: Wed Jan 05, 2005 7:55 am
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...
?>

Posted: Wed Jan 05, 2005 9:39 am
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);

Posted: Wed Jan 05, 2005 10:01 pm
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.

Posted: Thu Jan 06, 2005 8:43 am
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:

Posted: Thu Jan 06, 2005 8:45 am
by feyd
might want to check your bits there, bill ;)

Posted: Thu Jan 06, 2005 8:52 am
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?

Posted: Thu Jan 06, 2005 8:56 am
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.