-3

On my first page: page1.php I have an input where you type your desired name which I then want to be carried over to more than one page, so far I can get it to page2.php but on page3.php the code fails here is my code

page1.php:

       <form action="page2.php" method="post">
Name:  <input type="text" name="username" />
       <input type="submit" name="submit" value="Submit" />

\

page2.php: (after 5 seconds the page redirects to page3.php)

<?php
echo $_SESSION['username'] = $_POST['username'];
?>
<form action="page3.php" method="post">
<input type="hidden" name="username" />

page3.php:

<?php
echo $_SESSION['username'] = $_POST['username'];
?>     

These lines work on page2.php but not here which is what I can't seem to fix

Jack
  • 13
  • 6

2 Answers2

1

Instead of giving you a fish, I'll teach you to fish:

echo $_SESSION['username'] = $_POST['username'];

This statement is echoing the value ASSIGNED to $_SESSION['username']

  =  Assignment
 ==  Comparison
===  Comparison (Identical)
keyboardSmasher
  • 2,661
  • 18
  • 20
0

On page3.php is not working because you pass no value. So:

Instead of:

<input type="hidden" name="username" />

Go with:

<input type="hidden" name="username" value="".$_SESSION['username']."">

Or:

<input type="hidden" name="username" value="".$_POST['username']."">

Now it passes the value and you should get the value on page3.php. One warning is that users can edit your value with DEV tools so I suggest to pass values differently.

Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54