acctman Posted August 14, 2007 Share Posted August 14, 2007 Hi I need help cleaning up this coding. Is the "elseif" in the middle proper? It's looking to see if the username is admin and if so process the admin and pass if not then its a regular user and just send the Username if ($user_name == admin) { $password = "1234"; if(isset($_GET["user_name"])) $user_name = $_GET["user_name"]; if(isset($_GET["password"])) $password = $_GET["password"]; } elseif ($user_name != admin) { if(isset($_GET["user_name"])) $user_name = $_GET["user_name"]; else $isLoginValid = false; } Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/ Share on other sites More sharing options...
hostfreak Posted August 14, 2007 Share Posted August 14, 2007 Does the code work?... meaning does it do what you intend it to do? Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324036 Share on other sites More sharing options...
acctman Posted August 14, 2007 Author Share Posted August 14, 2007 no it's not working it seems to be skipping over the first set of IF statments and going to the bottom one. if i remove the $user_name == admin for the first IF statement set everything runs fine, same with the bottom. it doesn't seem to be checking the $user_name. its suppose to run the stuff underneath if user is ADMIN and if not then run the other stuff. if ($user_name == admin) { if(isset($_GET["user_name"])) $user_name = $_GET["user_name"]; else $isLoginValid = false; if(isset($_GET["password"])) $password = $_GET["password"]; else $isLoginValid = false; } elseif ($user_name != admin) { if(isset($_GET["user_name"])) $user_name = $_GET["user_name"]; else $isLoginValid = false; } Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324060 Share on other sites More sharing options...
roopurt18 Posted August 14, 2007 Share Posted August 14, 2007 Is there any reason you don't have quotes around admin in if($user_name == admin){ Also, stating: IF 1 THEN ... ELSE IF NOT 1 THEN ... END IF is redundant. Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324068 Share on other sites More sharing options...
acctman Posted August 14, 2007 Author Share Posted August 14, 2007 i found my problem it was this like $user_name == admin it should be $user_name = admin Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324072 Share on other sites More sharing options...
roopurt18 Posted August 14, 2007 Share Posted August 14, 2007 No it should not. You have broken your if statement even worse than before. Refer to this: http://www.phpfreaks.com/forums/index.php/topic,110618.msg447497.html#msg447497 Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324080 Share on other sites More sharing options...
acctman Posted August 14, 2007 Author Share Posted August 14, 2007 No it should not. You have broken your if statement even worse than before. Refer to this: http://www.phpfreaks.com/forums/index.php/topic,110618.msg447497.html#msg447497 you're right... i'll read that link thanks and report back Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324084 Share on other sites More sharing options...
acctman Posted August 14, 2007 Author Share Posted August 14, 2007 this method seems to be working fine, less coding and no errors so far. if(isset($_GET["user_name"])) $user_name = $_GET["user_name"]; else $isLoginValid = false; if($user_name == 'admin') { if(isset($_GET["password"])) $password = $_GET["password"]; else $isLoginValid = false; } Quote Link to comment https://forums.phpfreaks.com/topic/64934-solved-help-with-an-if-statement/#findComment-324121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.