user3599285
user3599285

Reputation: 91

PHP Form required checking only one entry

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 ?

Upvotes: 0

Views: 88

Answers (1)

GolezTrol
GolezTrol

Reputation: 116110

The function test_input doesn't exist. You have to write it first. Now you are calling a non-existent function, which results in a fatal error, which in turn ends your script.

Interestingly enough, there was this other user who also thought test_input was a built-in function. It is not.

Upvotes: 2

Related Questions