dimanche 1 décembre 2019

validating if statments for user inputs

if 2 of these are true both error links show up and messages on top of each other, if an input is 0 if statement that validates empty inputs also shows up also if input is not numeric but the other input is numeric php still calculates but just gives back what ever number you gave it plus the error code on top how do i fix?

first statement is to validate if any values are 0 and if operation is division to give error

if ($first == 0)
{ if ($operation == "Division")
  print("<h1>ERROR</h1>
        <p class=\"message\">YOU CAN NOT DIVIDE BY ZERO</p>");
}


else if($second == 0)
{ if ($operation =="Division")
  print("<h1>ERROR</h1>
        <p class=\"message\"> YOU CAN NOT DIVIDE BY ZERO</P>");
}

this if statement is to validate that the input is numeric

if (!is_numeric($first) or !is_numeric($second))
{
print("<h1> Error one or more inputs are not numbers</h1>" . "<p class=\"backlink\"><a href=\"calculator.html\">Go Back</a></p>");


}

third if statement is to validate for positive numbers

else if($first < 0 or $second < 0)
{
 print("<h1> Error one of more of your numbers is a negative</h1>" . "<p class=\"backlink\"><a href=\"calculator.html\">Go Back</a></p>");

}

this if statement validates empty inputs

   if (empty($first) or empty($second))
  {
 print("<p class=\"message\"> One or more input field is empty </p>" . "<p class=\"backlink\"><a href=\"calculator.html\">Go Back</a></p>");

}else{

Aucun commentaire:

Enregistrer un commentaire