i need a simple if else check whether any data is inserted to search or not.
So i set the condition ----
if the input data is less than 1 than it will show that the user should input some data to search. otherwise it will search the result.
But somehow this simple thing is not working for me.
Do anyone knows how to solve this problem. Thanks in advanced.
$query = $_POST['Search']; $min_length = 1; if (isset($query) && !empty($query)) { if (strlen($query) > $min_length){ // Check whether if there is atleast 1 character to chearch // method to search ..... echo($result); } else { echo "Sorry you have to put some data to search"; } this one always return the if statement it never go to the else statement.
i have also tried like so ---
$query = $_POST['Search']; $min_length = 1; if (isset($query) && ! empty($query) ) { if(isset($query) > $min_length){ // method to search ..... echo($result); } else { echo "Sorry you have to put some data to search"; } But this one always return the else statement.
Can anyone knows how to fix this problem.
not working- the 2nd code block problem is obvious (issetreturn truw or false, so its never greater than 1), but what happens when you try the 1st code blockisset($query) && !empty($query) && strlen($query) > $min_length- can be done with!empty($query)only.queryactually retrieving a value from$_POST['name']? Check withvar_dump($query);$queryis empty then it will never get inside the block with!empty($query)if there are no mistakes.