0

I want to display the information a user has submited on my registration forms, so I'm using

echo $_POST["name_of_field"], but for some reason the information isn't being displayed.

I have registerNewStudent2.php, registerNewStudent3.php, registerNewStudent4.php.

I want to display the registerNewStudent2.php forms in registerNewStudent4.php.

But from what I've read values in $_POST stay only for the next request.. So how can i do it? Here's my code:

registerNewStudent2.php

<form name="myForm" action="registerNewStudent3.php" onsubmit="return validate()" method="POST">
    <tr>
      <td>Nome</td>
      <td><input type="text" style="width:270px; color:gray" STYLE="color:gray" name="name"></td>
    </tr>

    <tr>
      <td>BI</td>
      <td><input type="text" style="width:270px; color:gray" name="BI";></td>
    </tr>

    <tr>
      <td>Curso</td>
      <td><input type="text" style="width:270px; color:gray" name="course"></td>
    </tr>
<input type="submit" value="Next">
</form>

registerNewStudent4.php

<?php
echo $_POST["name"];
echo $_POST["BI"];
echo $_POST["course"];
?>
vitorpnm
  • 7
  • 4
  • [You can use session to retain the information which is safer since the user will not be able to modify it after sent](http://stackoverflow.com/a/1535712/342740) – Prix Apr 18 '14 at 01:42

2 Answers2

0

The easiest way I've found would be to add a hidden field into the HTML with the PHP, like so:

<input type="hidden" name="name" value="<?php echo $_POST["name"]; ?>">

That way, when the form is submitted, a hidden variable will also be posted.

EDIT:

Alternatively, you can store them as $_SESSION variables, that will be accessible until the user navigates away from your website. Example: $_SESSION["name"]=$_POST["name"];

Helpful
  • 702
  • 4
  • 16
  • 1
    Easy? Yes! Secure? NO! By doing that the user can modify it at a later time if you change any of it or verify it during the first submit. – Prix Apr 18 '14 at 01:43
  • I've edited the answer to include info about `$_SESSION` variables. If the info doesn't need to be secure (and the OP has not stated it is necessary) then this is an easy (and easily-understood) way of handling it. – Helpful Apr 18 '14 at 01:44
  • Easier is, at least on occasion, 'right.' With this example, that's only when the information doesn't need to be secure. But I would certainly argue that this method is not inherently 'wrong.' – Helpful Apr 18 '14 at 01:48
  • Enlighten me, what occasion would make an insecure method right to use? Even if the information doesn't need to be secure it does not mean it can't be abused! Specially if he is using it for a 3 pages submit, where the 3rd page will send that information to the database then the user could easily cause several problems such as SQL Injection and others. – Prix Apr 18 '14 at 01:51
  • Prix, I believe we got off to a bad start: I'm not trying to be offensive, attacking, or otherwise obstinate in any way. I'm trying to give a comprehensive and understandable answer. OP did not state the information needed to be secure - though context may have shown that - but crying "SQL Injection" is going over the top. If using prepared statements, it wouldn't matter how often you passed info using this method. My understanding is that the intermediate page is used basically solely for display of information, which this works for. Validation should always occur before database entry. – Helpful Apr 18 '14 at 01:55
  • Indeed it wouldn't matter if the OP was not a beginner on PHP but since he seems to be as he didn't even know about session its unlikely he sanitize his data but that is not the question here, the thing I clearly showed you is that the data can be manipulated from one submit to another rendering it not only a bad approach but also **bad practice to show people starting up as it can become an habit.** – Prix Apr 18 '14 at 02:09
0

Save your data in session in the registerNewStudent2.php like this:

$_SESSION['name'] = $_POST['name'];

Then you can access those data in registerNewStudent4.php like this

echo $_SESSION['name'];

EDIT: In every page that you want to use session you must write first session_start() on the top of your page.

Almis
  • 3,684
  • 2
  • 28
  • 58