Forum Moderators: coopster
what I want is a series of PHP pages that validate and then if correct go onto the next page.
I can't seem to find an example that does both.
All I need to see is how it is done. Have I the wrong approach?
<html>
<body>
<?php
if ($submit) {
if ($pword1!= $pword2) {
$error = "Sorry! The passwords you have entered do not match.";
} else {
// process form
echo "Thank You!";
}
if (strlen($pword1) < 4){
$error ="Sorry! Your password must be at least 4 letters long.";
}
}
if (!$submit ¦¦ $error) {
echo $error;
?>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
Enter a user name <input type="text" name="first" value="<?php echo $first?>">
<br>
Choose a password <input type="text" name="pword1" value="<?php echo $pword1?>">
<br>
Renter password <input type="text" name="pword2" value="<?php echo $pword2?>">
<br>
<input type="Submit" name="submit" value="Enter Information">
</form>
<?php
} // end if
?>
</body>
</html>
take a look at this
in your version
if ($pword1!= $pword2) {
if the passwords matched it would say thank you and then do a few more checks. I changed it around a bit. The true test to see if it succeeds is
if (!$submit ¦¦ $error)
I just added an else to this statement and had that send it off to a thank you page using header [ca.php.net].
<?
if ($submit) {
if ($pword1!= $pword2) {
$error = "Sorry! The passwords you have entered do not match.";
}
if (strlen($pword1) < 4){
$error ="Sorry! Your password must be at least 4 letters long.";
}
}
if (!$submit ¦¦ $error) {
echo "<html><body>";
echo $error;
?>
<P>
<form method="post" action="<?= $PHP_SELF?>">
Enter a user name <input type="text" name="first" value="<?= $first?>">
<br>
Choose a password <input type="text" name="pword1" value="<?= $pword1?>">
<br>
Renter password <input type="text" name="pword2" value="<?= $pword2?>">
<br>
<input type="Submit" name="submit" value="Enter Information">
</form>
</body>
</html>
<?
} else {
header("Location: thankyou.html");
}
?>
I didn't test it but I believe thats right. Does that help you understand better? I also used a little shorthand.
<?= $first?>
is the same as
<?php echo $first;?>