Jump to content

If Statment running wrong?


AbydosGater

Recommended Posts

Hey, Ive been setting up a user managment system,
And i have a page that allows users to edit their info, as you would,

But after letting them fill the form, i stored their new information in variables! and now i want to make sure that nothing they entered is NULL or empty!

[quote]
//Check If The Updates Are Legal!
if ($newusername !== NULL || $newpassword !== NULL || $newemail !== NULL) {
$doupdates = "TRUE";
} else {
$doupdates = "FALSE";
}
[/quote]

So if none of them are NULL, it will do the updates, else dont do them,

But this isnt working because later down the script i have...

[quote]
if ($doupdates == "TRUE") {
echo "Do Update: TRUE";
} elseif ($doupdates == "FALSE") {
echo "<font color='#FF0000'><center><b>Please Note:<br>There Has Been An Error In The Information You Entered!<br>Please Go Back And Try Again!</b></center></font>";
}

[/quote]

I replaced my sql updates with an echo, just for small topic... but when i run the script, and i leave one or all of the form fields.. I just get The Do Update True, so what have i done wrong??

Thanks
Link to comment
https://forums.phpfreaks.com/topic/23472-if-statment-running-wrong/
Share on other sites

Try this

[code=php:0]//Check If The Updates Are Legal!
if ($newusername && $newpassword && $newemail) {
$doupdates = true;
}
else {
$doupdates = false;
}

if ($doupdates === true) {
echo "Do Update: TRUE";
}
elseif ($doupdates === false) {
echo "<font color='#FF0000'><center>Please Note:
There Has Been An Error In The Information You Entered!
Please Go Back And Try Again!</center></font>";
}[/code]

EDIT: changed the "||" (or) to "&&" (and) > I assume you want all to be entered, not just any one or more of them, change back if im wrong there
Ok i Changed it to...

[quote]if ($doupdates === TRUE) {
echo "Do Update: TRUE";
} elseif ($doupdates === FALSE) {
echo "<font color='#FF0000'><center><b>Please Note:<br>There Has Been An Error In The Information You Entered!<br>Please Go Back And Try Again!</b></center></font>";
}[/quote]

But now i get nothing,, no echos :P

EDIT:

Hey Sanfly..

Thanks, I know that the vars ARE set! i set them from my forms! i know there is a value, i want to check if the value is null, or if it actually has a value!

?
[quote author=AbydosGater link=topic=110999.msg449515#msg449515 date=1160429115]

Hey Sanfly..

Thanks, I know that the vars ARE set! i set them from my forms! i know there is a value, i want to check if the value is null, or if it actually has a value!

?
[/quote]

If the variables are empty, they will return false (or NULL), if there is a value, it returns true.  So, either

if($somevariable){
  echo "YAY";
}
elseif(!$somevariable){
echo "Bummer, its empty/null";
}

or

if(!empty($somevariable)){
echo "YAY";
}
elseif(empty($somevariable)){
echo "Bummer its empty/null";
}

should return the same thing in most cases

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.