Jump to content

Transfering variable from PHP page 1 then to page 2 and then to page 3

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
rt133813

rt133813

    Newbie

  • Members
  • Pip
  • 3 posts
Please Help, I'm trying to send a variable called zipcode from page 1 to page two and then to page three. I can get it to go from page 1 to page 2, but it will not transfer to page three. I have included my source. My option values go from page to page with no problem, but once again, trying to get a variable to go from page 1 to 2 to 3 to 4 ect. Can anyone please help me with this. I have included my source code below. Thanks

PAGE1.PHP
<?php session_start(); ?>

<form action="page2.php" method="post">
<select name="size">
      <option value="Small">Small</option>
      <option value="Medium">Medium</option>
      <option value="Large">Large</option>
    </select>

<select name="shape">
  <option value="Circle">Circle</option>
  <option value="Square">Square</option>
  </select>
    
    <select name="color">
  <option value="White">White</option>
  <option value="Black">Black</option>
  <option value="Red">Red</option>
</select>


<input name="zipcode" type="text" />


 <input type="image" name="submit" id="submit" src="next.jpg" onmouseover="this.src='nexthov.jpg'" onmouseout="this.src='next.jpg'" />
</form>

PAGE2.PHP
<?php session_start(); ?>
 
  <?php 
 $_SESSION['size'] = $_POST['size']; 
 $_SESSION['shape'] = $_POST['shape']; 
 $_SESSION['color'] = $_POST['color']; 
 $_SESSION['zipcode'] = $_POST['zipcode'];

 echo $_POST['size'];
 echo $_POST['shape'];
 echo $_POST['color'];

 echo $_POST['zipcode'];
?>

<form action="page3.php?<?php echo $_POST['zipcode']; ?>" method="post">


<?php 

$zipvalue = $_POST['zipcode'];

echo $zipvalue;

?>


<select name="option">
      <option value="Earth">Earth</option>
      <option value="Mars">Mars</option>
      <option value="Saturn">Saturn</option>
    </select>

<input type="image" name="submit" id="submit" src="next.jpg" onmouseover="this.src='nexthov.jpg'" onmouseout="this.src='next.jpg'" />
</form>

<a href="page1.php"><img src="back.jpg" width="65" height="55" border="0" /></a>

PAGE3.PHP
<?php session_start(); ?>


<?php
 
$_SESSION['option'] = $_POST['option'];
$_SESSION['zipcode'] = $_POST['zipcode'];

echo $_POST['option'];

echo $_POST['zipcode'];
?> 



<form action="page4.php" method="post">

<select name="option">
      <option value="Black">Black</option>
      <option value="White">White</option>
      <option value="Green">Green</option>
    </select>

<input type="image" name="submit" id="submit" src="next.jpg" onmouseover="this.src='nexthov.jpg'" onmouseout="this.src='next.jpg'" />

<a href="page2.php"><img src="back.jpg" width="65" height="55" border="0" /></a>

Edited by Alexander, 06 December 2010 - 03:45 PM.
([php] tags!)


#2
BlueMelon

BlueMelon

    Newbie

  • Members
  • PipPip
  • 28 posts
Look into '$_GET[]' You could transfer it by the action from the form.

#3
rt133813

rt133813

    Newbie

  • Members
  • Pip
  • 3 posts
Sorry, but am new at this and I have tried the $_GET['zipcode'] command but no luck. I'm sure I'm just not using the right syntax. Could you please provide me with an example. Thank you, and thanks for responding so quickly.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Your code is not so clear, for example in page three:
 
$_SESSION['option'] = $_POST['option'];
$_SESSION['zipcode'] = $_POST['zipcode'];

echo $_POST['option'];

echo $_POST['zipcode'];

You are overwriting whatever zipcode was in session with a non-existant zipcode from $_POST, and then you are echoing a non-existant zipcode from post, why not just work with sessions? Remember $_POST only works once on the page it was submitted to, it does not persist in other pages, only sessions do.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
rt133813

rt133813

    Newbie

  • Members
  • Pip
  • 3 posts
Thank you for pointing that out. Let's see if I can figure it out from here. Thanks for your reply.