EmperorJazzy Posted April 24, 2012 Share Posted April 24, 2012 Hi All, I'm having a major mind blank, and can't find anything in the previous posts resolving what I'm after. I'm setting $searchtext = $_POST['searchtext']; I want to check $seachtext is not null. I've seen isset($searchtext) but it doesn't solve my problem. Basiclaly; I want an if statement to say if(isset($searchtext)) {......} Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/261551-basic-code-help-variable-contents-checking/ Share on other sites More sharing options...
Jessica Posted April 24, 2012 Share Posted April 24, 2012 try if(strlen($_POST['searchtext'])) as this will check if the string has more than 0 characters. Quote Link to comment https://forums.phpfreaks.com/topic/261551-basic-code-help-variable-contents-checking/#findComment-1340217 Share on other sites More sharing options...
creata.physics Posted April 24, 2012 Share Posted April 24, 2012 Also take a look at php's trim function as it removes whitespace. if( trim( $_POST['searchtext'] ) != '' ) Will only allow the script to continue if actual characters were entered Quote Link to comment https://forums.phpfreaks.com/topic/261551-basic-code-help-variable-contents-checking/#findComment-1340220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.