I have two forms the first is page1.php and the second is called page2.php. I have a session which I am trying to pass variables with. However, when I redirect to page2.php using
Code: Select all
header( 'Location: page2.php' ) ;page1.php
Code: Select all
<?php
session_start();
$_SESSION['Name'] = $sender_name;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// Define a variable for the email form input "Name"
$sender_name = $_POST['Name'];
// Create an empty array to hold the error messages.
$SC_Errors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
// If the email form input "Name" is empty
if ($sender_name=='')
// Define a variable for the error message
$SC_Errors['Name'] = 'Enter Your Name.';
if ($sender_name=='Your Name')
// Define a variable for the error message
$SC_Errors['Name'] = ' Please Provide Your Name.';
// If the form input "Name" is only letters
if(preg_match("#^[A-Za-z' ]*$#",$sender_name)) {
$success;
}else {
$SC_Errors['Name'] = 'Invalid Name.';
}
// If the error array is empty, there were no errors.
if (count($SC_Errors) == 0) {
header( 'Location: page2.php' ) ;
}
else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$scError = '<div class="formerror"><p><img src="alert.png" width="16" height="16" name="alert" id="alert" alt="alert" />Please review the form and correct the following errors:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($SC_Errors as $error) {
$scError .= "<li>$error</li>";
}
$scError .= '</ul></div>';
}
}
?>
<div align="center" class="SCerror">
<table>
<tr>
<td>
<?php echo $scError; ?>
</td>
</tr>
</table>
</div>
<div align="center">
<form name="SCform" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h3>Your Information</h3>
<hr/>
<!-- Input: Name -->
<table>
<tr>
<td>
<table>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<div <?php if (!empty($SC_Errors['Name'])) echo ' class="SCinput"'; ?> align="center">
<input name="Name" id="Name" type="text" style="color:#000000; position:static" onfocus="this.style.color = '#ccc' ; clickclear(this, 'Your Name');" onblur="this.style.color = '#000' ; clickrecall(this,'Your Name');" value="Your Name" />
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div <?php if (!empty($SC_Errors['Name'])) echo ' class="SCerror"'; ?> align="center">
<?php if (!empty($SC_Errors['Name'])) echo '<b> '.$SC_Errors['Name'].' </b>'; ?>
</div>
</td>
</tr>
</table>
<!-- Input: Name -->
<br />
<input type="reset" value="Reset" name="Reset"> <input type="submit" name="Submit" value="Submit" />
</form>
</div>
</body>
</html>
and the second page called page2.php
Code: Select all
<?php
session_start(); // This connects to the existing session
session_register ("Name"); // Create a session variable called name
$_SESSION['Name'] = $sender_name; // Set name = form variable $sender_name
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
/* Gather Input Form Variables */
// Define a variable for the email form input "Name"
$sender_name = $_POST['Name'];
// Create an empty array to hold the error messages.
$SC_Errors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
// If the email form input "Name" is empty
if ($sender_name=='')
// Define a variable for the error message
$SC_Errors['Name'] = 'Enter Your Name.';
if ($sender_name=='Your Name')
// Define a variable for the error message
$SC_Errors['Name'] = ' Please Provide Your Name.';
// If the form input "Name" is only letters
if(preg_match("#^[A-Za-z' ]*$#",$sender_name)) {
$success;
}else {
$SC_Errors['Name'] = 'Invalid Name.';
}
// If the error array is empty, there were no errors.
if (count($SC_Errors) == 0) {
header( 'Location: page2.php' ) ;
}
else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$scError = '<div class="formerror"><p><img src="alert.png" width="16" height="16" name="alert" id="alert" alt="alert" />Please review the form and correct the following errors:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($SC_Errors as $error) {
$scError .= "<li>$error</li>";
}
$scError .= '</ul></div>';
}
}
?>
<div align="center" class="SCerror">
<table>
<tr>
<td>
<?php echo $scError; ?>
</td>
</tr>
</table>
</div>
<div align="center">
<form name="SCform" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h3>Your Information</h3>
<hr/>
<!-- Input: Name -->
<table>
<tr>
<td>
<table>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<div <?php if (!empty($SC_Errors['Name'])) echo ' class="SCinput"'; ?> align="center">
<input name="Name" id="Name" type="text" style="color:#000000; position:static" onfocus="this.style.color = '#ccc' ; clickclear(this, 'Your Name');" onblur="this.style.color = '#000' ; clickrecall(this,'Your Name');" value="Your Name" />
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div <?php if (!empty($SC_Errors['Name'])) echo ' class="SCerror"'; ?> align="center">
<?php if (!empty($SC_Errors['Name'])) echo '<b> '.$SC_Errors['Name'].' </b>'; ?>
</div>
</td>
</tr>
</table>
<!-- Input: Name -->
<br />
<input type="reset" value="Reset" name="Reset"> <input type="submit" name="Submit" value="Submit" />
</form>
</div>
</body>
</html>
can anyone please help me?