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. Link to comment https://forums.phpfreaks.com/topic/16891-how-deep-nested-elseif-can-manage/ 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] Link to comment https://forums.phpfreaks.com/topic/16891-how-deep-nested-elseif-can-manage/#findComment-71124 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. Link to comment https://forums.phpfreaks.com/topic/16891-how-deep-nested-elseif-can-manage/#findComment-71178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.