jsk1gcc Posted January 4, 2011 Share Posted January 4, 2011 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/223318-post-var-across-multiple-pages/ Share on other sites More sharing options...
joel24 Posted January 4, 2011 Share Posted January 4, 2011 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']; Quote Link to comment https://forums.phpfreaks.com/topic/223318-post-var-across-multiple-pages/#findComment-1154453 Share on other sites More sharing options...
jsk1gcc Posted January 4, 2011 Author Share Posted January 4, 2011 awesome will give it a try in the morning, will let you know how it works out Quote Link to comment https://forums.phpfreaks.com/topic/223318-post-var-across-multiple-pages/#findComment-1154463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.