-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
  • 1
    format properly please –  Jun 12 '16 at 05:54
  • 1
    I'm not clear why there are paragraph elements all over your code. Please format your code, http://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks. Are you using `` on all pages? – chris85 Jun 12 '16 at 05:56
  • Possible duplicate of [How do I pass data between pages in PHP?](http://stackoverflow.com/questions/1179559/how-do-i-pass-data-between-pages-in-php) – Jonathan Eustace Jun 12 '16 at 06:06
  • I suggested an edit. – Gytis TG Jun 12 '16 at 06:43

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,516
  • 17
  • 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.

Gytis TG
  • 6,945
  • 17
  • 35
  • 52