Jump to content

POST var across multiple pages?


jsk1gcc

Recommended Posts

Hi again =)

 

I have an index.php where the var $result comes from a drop down box when i press submit that var gets passed to a redirect page and used in an if query to direct the user to one of three pages.

 

I want to carry that choice from the first drop down ($result) to the customer input page.

 

here's the code =)

 

index.php

<?php
//connect  include
require("connect.php");
#"
      echo '<form method="post" name="f1" action="redirect.php">';
$query = "SELECT DISTINCT name FROM `ride` ORDER BY name DESC";  
$result = mysql_query($query);  

echo"<select name='name'<option value=''>Select Ride</option>";
	while( $row = mysql_fetch_array($result) ) 
	{ 
    		echo '<option>'.$row['name'].'</option>'; 
	}  
		echo '</select>'; 
mysql_free_result( $result ); 

echo "<input type='submit' value='Submit'>";
echo "</form>";
?>

 

redirect.php

<?php

require ('connect.php');
$result=$_POST['name'];

//redirect code
  if ($result == "Swinging Ship") {
header('Location: Swing.php');
} elseif ($result == "Roller Coaster") {
header('Location: Roller.php');
} elseif ($result == "Ice Blast") {
header('Location: Ice.php');
} 

?>

 

Swing.php

<?php
//connect  include
require("connect.php");
$result=$_POST ['name'];

//extract data
$extract =mysql_query("SELECT * FROM ride WHERE rideID ='1'");
$numrows = mysql_num_rows($extract);

//start of form
echo '<form method="post" name="f1" action="formOne.php">';
echo 'Please choose a seat:  '; echo"<select name='seat'>";
	while( $row = mysql_fetch_assoc($extract)) 
	{ 
		$rideID = $row ['rideID'];
		$name = $row ['name'];
		$seatNumber = $row ['seatNumber'];
		$time = $row ['time'];
		$price = $row ['price'];
		echo "<option name='ride'> $seatNumber </option>";
	}  
echo '</select><br>'; 
mysql_free_result( $extract ); 

//show time and price
echo "The price of the ride is: £$price<br>The duration if of the ride is: $time minutes<br>" ;

//submit button
echo "<input type='submit' value='Submit'>";
echo "</form>";
?>

 

formOne.php

<?php 

require ('connect.php');
$extract=$_POST['seat'];
$result=$_POST['name'];

echo " <p> the seat choosen is : $extract <p> ";
echo " <p> the ride choosen is : $result <p> ";

?>

 

so as you can see the ride name has to go from index to formOne and further for inserting and deleting records etc..The question i guess i'm asking is how do i make results from drop down boxes or any query accessible to the entire site?

 

Thanks in advance =)

Link to comment
https://forums.phpfreaks.com/topic/223318-post-var-across-multiple-pages/
Share on other sites

set it in the session variables,

 

//ensure this line is at the top of each page
session_start(); 

//now you can set session variables
$_SESSION['myVariable']=$_POST['name'];

//now on the 2nd page make sure you have session_start(); up the top and you'll be able to call $_SESSION['myVariable'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.