Page 1 of 1

Pass variables from one Script to another

Posted: Thu Apr 01, 2010 1:54 pm
by SecretAgentX9
I'm new to PHP, only about 3 months in. I'm trying to take a form a user fills out, check the $_POST variables to make sure all is good and if it is then I want to send those variables to a new page to be displayed. If there are Errors then it displays it above the form. Right now I have two outside scripts that check to make sure the email is a valid one and then if all is good another script to mail those variables. On to the code

Code: Select all

require('validemail.php');
require('mailsuccess.php');

$Errors = '';

if(isset($_POST['submit']))
{

$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Phone'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$ConfirmEmail = Trim(stripslashes($_POST['ConfirmEmail']));
$Hdd = Trim(stripslashes($_POST['Hdd']));
$Warranty = Trim(stripslashes($_POST['Warranty']));
$Message = Trim(stripslashes($_POST['Message']));
$Captcha = Trim(stripslashes($_POST['Captcha']));

if (validemail($Email)){

// Make sure the required Fileds are completed and the email addresses match
if (empty($Name)) { $Errors .= "\n Please enter your name."; }
if (empty($Tel)) {$Errors .= "\n Please enter your telephone number."; }
if ($Email !== $ConfirmEmail) {$Errors .= "\n Your email addresses don't match."; }
if ($Captcha !== '4') {$Errors .= "\n The Captcha is incorrect."; }
if (empty($Errors)) {

success($Name, $Tel, $Email, $Hdd, $Warranty, $Message);

/* Here is where I'm trying to figure out how to send the variables to the new page to be displayed */
}
}
else { $Errors .= "\n Please enter a valid email."; }
}

Re: Pass variables from one Script to another

Posted: Thu Apr 01, 2010 3:12 pm
by AbraCadaver

Code: Select all

session_start();  // if your sucess() function outputs anything then this line will need to be before success()
$_SESSION = compact('Name', 'Tel', 'Email', 'Hdd', 'Warranty', 'Message'); // this is kinda sloppy, you can also do
//$_SESSION['Name'] = $Name;
//etc...
header('Location: http://example.com/yourpage.php');
exit;
Then as the first line of yourpage.php you need:

Code: Select all

session_start();
Then use the variables:

Code: Select all

$Name = $_SESSION['Name'];
echo $name;
//or just
echo $_SESSION['Name'];

Re: Pass variables from one Script to another

Posted: Thu Apr 01, 2010 3:47 pm
by SecretAgentX9
Thank you!