elis Posted February 26, 2007 Share Posted February 26, 2007 I have the following code: if(!$username==""){ $qCheck = "select * from .... (I didn't put the full code, because I didn't think it was vital - if anyone thinks it is let me know, and I'll add it.) ($username is a $_post[...] field from an input box) Which is for if the $username field isn't empty, to run a a check on it and output a specific result. However, when the $username field is empty, the script stops running. Is there any way I can get the script to ignore if the $username field is empty, and continue running? Link to comment https://forums.phpfreaks.com/topic/40216-ignore-a-statement/ Share on other sites More sharing options...
nloding Posted February 26, 2007 Share Posted February 26, 2007 You'll have to post the code after the IF statement. You can either take out the IF statement, or there isn't anything after the IF statement to parse when the username is empty. If there is code after the IF statement, that should process if the username is blank. Link to comment https://forums.phpfreaks.com/topic/40216-ignore-a-statement/#findComment-194587 Share on other sites More sharing options...
JBS103 Posted February 26, 2007 Share Posted February 26, 2007 if(!$username==""){ $qCheck = "select * from .... To begin with I would use either if(isset($username)) or if($username != "") The way you have it seems convoluted to me. But now, if you want it to run, when the $username has a value, put the code inside the If. If you want it to do nothing when the $username is blank, than just put the next step of code outside of the If, similar to what nloding was saying. Link to comment https://forums.phpfreaks.com/topic/40216-ignore-a-statement/#findComment-194645 Share on other sites More sharing options...
nloding Posted February 26, 2007 Share Posted February 26, 2007 There's a million different ways to do it, all with the same result. Personally, in the IF statement, I would put what happens if $username doesn't exist, and have the rest of the code as the else, because usually there's more code if it exists. if(!$username) { }else{ } //or if(empty($username)) { }else{ } Link to comment https://forums.phpfreaks.com/topic/40216-ignore-a-statement/#findComment-194696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.