mardi 12 juillet 2016

else if returning true when false

Im trying to figure out why my elseif statement is returning the else if $name < 5 true even tho I enter fields greater than 5 , it should be echoing out "Great" if all are false! I set the $name and $score var to '' because im using this in the html values which i dont want to error undefined, new to php thanks

<!DOCTYPE html>
<?php



$name = '' ;
$score = '' ;
$message = '';

if (isset($_POST['name'])){

 $name = $_POST["name"];
 $score = $_POST["score"];

 if (!$name || !$score) {

    $message = "Please fill in both name and score!";

 } elseif ($name < 5) {

   $message = "name must be at least 5 characters";


 } elseif ($score < 5) {

     $message = "score must be at least 5 characters";

 } else {

   echo 'Great';

 }

}



?>



<h1>Enter Your info </h1>
<hr>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
    Name: <input type="text" name="name" placeholder="Enter Name" value="<?  php echo $name;  ?>"> <br>
    Score: <input type="text" name="score" placeholder="Enter Score" value="    <?php echo $score;  ?>">
    <hr>
    <input type="submit" name="submit" value="add">

</form>
<p class="error">
  <?php echo $message ;  ?>
</p>




</body>
</html>

Aucun commentaire:

Enregistrer un commentaire