Carry $_POST value one page to another?
Posted: Sat Mar 15, 2008 7:05 pm
Hi everyone,
I wrote a simple form, and I want to make sure the user has entered values in my fields before forwarding them to my next page. My code is here:
If the user has filled in my fields, they should be taken to this page upon submission:
My variables are not being echoed on the results page. Any idea why not?
Or maybe a better question, is there a better way to verify a user has entered data into a form field before sending the values to another script?
Thanks!
I wrote a simple form, and I want to make sure the user has entered values in my fields before forwarding them to my next page. My code is here:
Code: Select all
<?PHP
$name=$_POST['name'];
$age=$_POST['age'];
if ($_POST['submit'] == "Submit")
{
if ($_POST['name'] == "")
{
$name_error="You did not enter your name.";
}
else if ($_POST['age'] == "")
{
$age_error="You did not enter your age.";
}
else
{
header("Location: results.php");
}
}
?>
<head>
</head>
<body>
<form action="" method="post" name="simpletest">
Name:<br /><?PHP echo $name_error; ?>
<input name="name" type="text" value="<?PHP echo $name; ?>" />
<br />
Age:<br /><?PHP echo $age_error; ?>
<input name="age" type="text" value="<?PHP echo $age; ?>" />
<br />
<input name="submit" type="submit" value="Submit" />
<input name="clear" type="reset" value="Clear" />
</form>
</body>
</html>Code: Select all
<?PHP
$name=$_POST['name'];
$age=$_POST['age'];
?>
<head>
</head>
<body>
<?PHP
echo "Your name is: ".$name." and you are ".$age." years old.";
?>
</body>
</html>Or maybe a better question, is there a better way to verify a user has entered data into a form field before sending the values to another script?
Thanks!