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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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