I got a problem with my code. I want to figure out if there is a specific number in the text box and if it's empty it should say something like "There's nothing inside".
I did so but got a problem if the text box is empty. If it's empty it skips the code for checking if it's empty, proceeds with the function after it.
That's what I got so far.
<?php
if(isset($_POST["submit"])){
$name = $_POST['winner'];
if(strpos($name,'123456789') !== false){
echo "<br><br>".$name." was the correct answer! Congratulations!";
}elseif($name !== ""){
echo "<br><br>You haven't typed in a number.";
}else{
echo "<br><br>".$name." wasn't correct. Better luck next time.";
}
}
?>
Anyone know what the error is?
This statement:
}elseif($name !== ""){
Should be:
}elseif ($name === ""){
Or:
}elseif (!strlen($name)){
I think you meant the opposite.
Should be elseif($name === "")
not elseif($name !== "")
or also elseif(empty($name))
you want that if user leave text field empty it again ask for that ...
give me your email I'll mail you an example. ....