I'm using PHP in my project and when any form is submitted I need to check if the input it not empty, so I use something like this:
if(empty($myVar)) {
echo "Error";
} else {
echo "success";
}
But this doesn't seem to be working as I want, so If the user enter empty space like " " so between the quotation is nothing but emptiness, but still PHP showing success message instead of error message.
I used isset($var) also, but its the samething, not working as I need.
What could be the problem? and How to solve it?
Use trim function, which removes spaces in the beginning and in the end of a string:
if(empty(trim($myVar))) {
echo "Error"
} else {
echo "success";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With