I have a php form (code to follow) with a submit button that runs JSON-events.php
as its action
(method = POST
). In the JSON-events co
Do not use
if (!empty($_POST)) {
to check if there is a post done use this:
if( $_SERVER['REQUEST_METHOD'] == 'POST') {
Conditions that you can use with $_POST
if(count($_POST)>0){
//...
}
if(isset($_POST['field_name'])){
//...
}
if( $_SERVER['REQUEST_METHOD'] == 'POST') {
//..
}
Using empty() will fail if value 0 is posted
So it is better to use
isset($_POST['FIELD_NAME'])
empty()
will work if $_POST
does not have any values (Empty array), but in your case when you submit without any values still you get an array like below and it's not empty:
Array ( [searchlat] => [searchlong] => [search] => Submit Query )
empty()
will return true only if $_POST
returns
Array (
)
But it's not going to happen as every form will have one Sumbit button.
Just use
if($_POST) {
//php code
}
It will solve your problem.
Learn more about empty() by visiting http://php.net/manual/en/function.empty.php
Try this
if(!empty($_POST['search']) && isset($_POST['search']))
much better to check for an actual value in the $_POST array. Eg.
if (!empty($_POST['search']))