bilis_money Posted August 8, 2006 Share Posted August 8, 2006 i'm trying to make a nested elseifok, here are the codes,[code]//check for empty fields if($user == ''){ $COerr_msgs->err_msgs('register1'); } else if($pass == ''){ $COerr_msgs->err_msgs('register1'); } else { //compare username into database if($user_new == $user_old) { if($pass_new == $pass_old) { //check activated if set if set then proceed to authorized page. if(activate_sta == '1') { include "authorize_page.php"; } else { $COerr_msgs->err_msgs('login1'); } } else { $COerr_msgs->err_msgs('register2'); exit(); } } elseif($user_new != $user_old) { $COerr_msgs->err_msgs('activated2'); exit(); } }[/code]I don't how deep an elseif condition can manage.but i think i have experiencing confusion becausethe first else condition of the elseif does't threw methe right error message, but instead it mere display nothing?just a blank page.I don't know if i had mistake with that codes, and i don't knowif there are some hidden rules about nested elseif.ok, i'll try to review my codes while i'm awaiting for your comments.thanks in advance. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 8, 2006 Share Posted August 8, 2006 There's no benefit to nesting two tests that both cause identical results. This works fine:[code]if (($user == '') || ($pass == '')) { $COerr_msgs->err_msgs('register1');} [/code] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 8, 2006 Share Posted August 8, 2006 I can never understand why people do not align their opening and closing braces! It makes it so much easier to spot errors.Example:[code] if($user == '') { $COerr_msgs->err_msgs('register1'); } else if($pass == '') { $COerr_msgs->err_msgs('register1'); } else { //compare username into database if($user_new == $user_old) { if($pass_new == $pass_old) { //check activated if set if set then proceed to authorized page. if(activate_sta == '1') { include "authorize_page.php"; } else { $COerr_msgs->err_msgs('login1'); } } else { $COerr_msgs->err_msgs('register2'); exit(); } } elseif($user_new != $user_old) { $COerr_msgs->err_msgs('activated2'); exit(); } }[/code]Identical to your code but so much easier to read! Well I think so anyway, YMMV. Quote Link to comment 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.