I am new to PHP and this is my code for a checking all inputs in a form :
<html>
<body>
<?php
$name = $email = $password = $confirmpassword = $number = "";
$error= false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
echo"Name is required<br>";
$error=true;
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["password"])) {
echo "Password is required<br>";
$error=true;
} else {
$password = test_input($_POST["password"]);
}
if (empty($_POST["email"])) {
echo "Email is required<br>";
$error=true;
} else {
$email = test_input($_POST["email"]);
}
if (empty($_POST["confirmpassword"])) {
echo "Confirm Password is required<br>";
$error=true;
} else {
$confirmpassword = test_input($_POST["confirmpassword"]);
}
if (empty($_POST["number"])) {
echo "Number is required<br>";
$error=true;
} else {
$number = test_input($_POST["number"]);
}
if(strcmp($password,$confirmpassword)!=0)
{
echo "Password do not match<br>";
$error=true;
}
if(!$error)
{
}
}
?>
</body>
</html>
If I enter an input in the first textbox ie name it displays a blank page and does not show the other errors. That is the errors because the other inputs have not been entered. So in other words it shows errors for each of the inputs until and unless a true statement has been detected, After any of the statements are true the code after that statement does not seem to execute. Basically if any true statement is encountered the code breaks and ends.
How do i fix this ?
Aucun commentaire:
Enregistrer un commentaire