Jump to content

ignore a statement


elis

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.