Jump to content

How deep nested elseif can manage?


bilis_money

Recommended Posts

i'm trying to make a nested elseif

ok, 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 because
the first else condition of the elseif does't threw me
the 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 know
if 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

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.

Archived

This topic is now archived and is closed to further replies.

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