PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This is the Code, the problem is when someone doesn't enter a search text, it shows an error, what i want is when someone didn't enter a search term that the page print something like "You didn't enter a search term" :
if (isset($_GET['query']) && empty($_GET['query'])) {
echo 'Enter search term';
}
else {
// do everything else
}
This is where you need to figure out if they actually have even submitted the form with no data or they haven't submitted it at all. I'd use a combination of isset() and empty().
if (isset($_GET['query']) && empty($_GET['query'])) {
echo 'Enter search term';
}
else {
// do everything else
}
This is where you need to figure out if they actually have even submitted the form with no data or they haven't submitted it at all. I'd use a combination of isset() and empty().
That's pointless because empty() checks for the existence of the variables just as isset() does, except it checks to make sure the variable is not empty as well.
if (isset($_GET['query']) && empty($_GET['query'])) {
echo 'Enter search term';
}
else {
// do everything else
}
This is where you need to figure out if they actually have even submitted the form with no data or they haven't submitted it at all. I'd use a combination of isset() and empty().
That's pointless because empty() checks for the existence of the variables just as isset() does, except it checks to make sure the variable is not empty as well.
Yes, think about it
You open google.com for the first time. Now if it told you that you haven't entered a search query would that seem confusing? If you then proceeded to hit submit without entering any text and it said you've not entered a query qould it make sense?
The isset() checks that the user actually submitted the form, then the empty() checks if any data was sent by the user. Just using empty() doesn't allow you that knowledge since empty() matches: