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
Share on other sites

You if statement is wrong (($doupdates == "TRUE")).
You are checking if $doupdates is the string "TRUE".

You can either do-
if($doupdates)
or
if($doupdates === TRUE)

Same goes for the false, if($doupdates === FALSE) or if(!$doupdates).

Orio.
Link to comment
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
Link to comment
Share on other sites

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!

?
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.