AbydosGater Posted October 9, 2006 Share Posted October 9, 2006 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 More sharing options...
Orio Posted October 9, 2006 Share Posted October 9, 2006 You if statement is wrong (($doupdates == "TRUE")).You are checking if $doupdates is the string "TRUE".You can either do-if($doupdates)orif($doupdates === TRUE)Same goes for the false, if($doupdates === FALSE) or if(!$doupdates).Orio. Link to comment https://forums.phpfreaks.com/topic/23472-if-statment-running-wrong/#findComment-106499 Share on other sites More sharing options...
sanfly Posted October 9, 2006 Share Posted October 9, 2006 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 https://forums.phpfreaks.com/topic/23472-if-statment-running-wrong/#findComment-106503 Share on other sites More sharing options...
AbydosGater Posted October 9, 2006 Author Share Posted October 9, 2006 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 :PEDIT: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 https://forums.phpfreaks.com/topic/23472-if-statment-running-wrong/#findComment-106506 Share on other sites More sharing options...
alpine Posted October 9, 2006 Share Posted October 9, 2006 [code]<?phpif(empty($_POST['var'])){// empty}if(!empty($_POST['var'])){// NOT empty}?>[/code] Link to comment https://forums.phpfreaks.com/topic/23472-if-statment-running-wrong/#findComment-106511 Share on other sites More sharing options...
sanfly Posted October 9, 2006 Share Posted October 9, 2006 [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, eitherif($somevariable){ echo "YAY";}elseif(!$somevariable){ echo "Bummer, its empty/null";}orif(!empty($somevariable)){ echo "YAY";}elseif(empty($somevariable)){ echo "Bummer its empty/null";}should return the same thing in most cases Link to comment https://forums.phpfreaks.com/topic/23472-if-statment-running-wrong/#findComment-106527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.