Jump to content

Passing variables between pages


AdRock

Recommended Posts

I have a registration form which takes some POST variables and validates user input which works fine (apart from some of the regex).

 

I would like these variables passed from the registration form to another page which is the registration success page but I can't get the variables to pass between pages.

 

I have used global before the variable names but it still doesn't work

 

These are some of the variables i want to pass

//set up some global variables to be passed between validation function and form
global $_POST, $error, $print_again, $register, $message;
global $first_name, $last_name;
global $houseno, $street, $town, $county, $postcode, $telephone;
global $email1, $email2, $username, $password1, $password2; 

//variables for checking the user's name
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];

//variable for checking the user address and telephone
$houseno = $_POST['houseno'];
$street = $_POST['street'];
$town = $_POST['town'];
$county = $_POST['county'];

 

this is a cut down version of the page i want the varaibles passed to

<?php
global $first_name;
echo "<h1>".$first_name."</h1>";
?>

 

Is there a simple way of passing these variables or have i got to create a session to do it?

Link to comment
https://forums.phpfreaks.com/topic/95129-passing-variables-between-pages/
Share on other sites

EDIT: beaten to it  ;)

 

2 ways i know of....

 

1:

log the user in. and in the session, store the id of the user.

then on the next page, grab that info from the session, and use a query to draw that info...

this is probably the easiest way... do you know how to store info in sessions?

this is probably the most secure too.

 

OR

2:

well after the account was created... do this..

echo "<meta http-equiv='refresh' content='0;url=success.php?id=<?php echo $id ?>'>";

then on the success.php page, use this code...

 

<?php
function sql_quote($data) {
  if (get_magic_quotes_gpc()) {
  $data = stripslashes($data);
  }

return addslashes($data);
}
$id= sql_quote($_GET['id']);
and query to get that info for this id.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.