2013-05-18 49 views
0

想我嘗試獲取先前的$變量(register_detail.php)至$ _ POST(register_submit.php)

例如:

register_detail.php

<form action="register_submit.php" method='POST'> 
<table> 
<tr><td>Name:</td> <td><?php print ($name); ?></td></tr> 
<tr><td>I/C:</td> <td><?php print ($ic); ?></td></tr> 
<tr><td>e-mail:</td> <td><?php print ($email); ?></td></tr> 
<tr><td>Address:</td> <td><?php print ($address); ?></td></tr> 
<tr><td>Date of Birth:</td> <td><?php print ($dob); ?></td></tr> 
<tr><td>Contact:</td> <td><?php print ($contact); ?></td></tr> 
</table> 
<?php $password; ?> -- this was not meant to be displayed -- 


<input type='submit' name='submit' value='Confirm'><input type='button' value='Cancel' onclick='history.go(-1);return false;'/> 
</form> 

到新的PHP(register_submit.php)

if (isset($_POST['name']) && isset($_POST['ic']) && isset($_POST['email']) && isset($_POST['address']) && isset($_POST['dob']) && isset($_POST['contact']) && isset($_POST['password'])) 
      $name  = $_POST['name']; 
      $ic  = $_POST['ic']; 
      $email  = $_POST['email']; 
      $address = $_POST['address']; 
      $dob  = $_POST['dob']; 
      $contact = $_POST['contact']; 
      $password = $_POST['password']; 

正如我們所看到的,我可以賣到$變量$ _ POST?

+0

將舊值的形式隱藏的輸入,你可以在形式,許多隱藏的變數。 – Barmar

+0

我該怎麼做?在​​標記? –

+0

如果你不想被顯示!使用'cookie'或'session' – senK

回答

3

將值放入隱藏的輸入中。他們可以在任何形式的任何地方。

<form action="register_submit.php" method='POST'> 
    <table> 
    <tr><td>Name:</td> <td><?php print ($name); ?></td></tr> 
    <tr><td>I/C:</td> <td><?php print ($ic); ?></td></tr> 
    <tr><td>e-mail:</td> <td><?php print ($email); ?></td></tr> 
    <tr><td>Address:</td> <td><?php print ($address); ?></td></tr> 
    <tr><td>Date of Birth:</td> <td><?php print ($dob); ?></td></tr> 
    <tr><td>Contact:</td> <td><?php print ($contact); ?></td></tr> 
    </table> 
    <input type="hidden" name="name" value="<?php echo $name; ?>"> 
    <input type="hidden" name="password" value="<?php echo $password; ?>"> 
    <input type="hidden" name="ic" value="<?php echo $ic; ?>"> 
    ... repeat for all the fields 

    <input type='submit' name='submit' value='Confirm'><input type='button' value='Cancel' onclick='history.go(-1);return false;'/> 
</form> 
+0

謝謝你們,這是輝煌的 –

0

您可以使用隱藏變量爲你的目的.. 你也不必關心該表的結構。由於他們沒有對UI進行顯示的準備,你可以把它們徘徊無論你想內

<form> 
<table> 
</table> 
<input type='hidden' name='whatever' value="<?php echo $var;?>" /> 
</form> 

,只要你想