break out of IF statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jay

    break out of IF statement

    G'day all



    This registration form checks for the submit button then displays the next form from the include statement. But before it displays the next form it will check to make sure the user has entered details correctly and give error messages of whats missing before displaying the original form again. My problem is that I can't exit from the 'if' statement, it brings up the first form as desired, but I can't get it to quit there. I tried using the break; function but it needs to be in a 'do while' sort of loop before it will let you break out of it. I tried putting the if statement inside a do while like this one





    do {

    if ($cond1) {

    ...

    }

    } while(0);







    Bt I couldn't seem to get it to work, probably because part of the code is being included? Any ideas? All I want it to do is stop processing the rest of the IF statement in registration.ph p. This is the error message

    Fatal error: Cannot break/continue 1 level







    Registration.ph p

    <?





    if ($register1) {



    include("includ es/registration1-check.inc.php") ;

    include("includ es/registration2.i nc.php");



    } elseif ($register2) {



    include("includ es/registration3.i nc.php");



    } else {



    include("includ es/registration1.i nc.php");



    }





    ?>



    registration1-check.inc.php

    <?

    // reset errorstop

    $errorstop = 0;



    if (!$username) {

    $error = "Please enter a username<br>";

    echo $error;

    $errorstop = 1;

    }



    if (!$password1) {

    $error = "Please enter a Password<br>";

    echo $error;

    $errorstop = 1;

    }





    if ($errorstop == 1 ) {

    // show the original form again

    include("includ es/registration1.i nc.php");

    break;

    }

    ?>

  • Chung Leong

    #2
    Re: break out of IF statement

    In registration1-check.inc.php return $errorstop, then structure your loop in registration.ph p like this:

    if ($register1) {



    if(!include("in cludes/registration1-check.inc.php") ) {

    include("includ es/registration2.i nc.php");

    }

    }



    But what you should do is restructure your code. Using include files in this manner is a very bad practice.

    Uzytkownik "Jay" <gybrid@hotmail .com> napisal w wiadomosci news:bt7h4e$2ck 0$1@bigblue.net .au...
    G'day all



    This registration form checks for the submit button then displays the next form from the include statement. But before it displays the next form it will check to make sure the user has entered details correctly and give error messages of whats missing before displaying the original form again. My problem is that I can't exit from the 'if' statement, it brings up the first form as desired, but I can't get it to quit there. I tried using the break; function but it needs to be in a 'do while' sort of loop before it will let you break out of it. I tried putting the if statement inside a do while like this one





    do {

    if ($cond1) {

    ...

    }

    } while(0);







    Bt I couldn't seem to get it to work, probably because part of the code is being included? Any ideas? All I want it to do is stop processing the rest of the IF statement in registration.ph p. This is the error message

    Fatal error: Cannot break/continue 1 level







    Registration.ph p

    <?





    if ($register1) {



    include("includ es/registration1-check.inc.php") ;

    include("includ es/registration2.i nc.php");



    } elseif ($register2) {



    include("includ es/registration3.i nc.php");



    } else {



    include("includ es/registration1.i nc.php");



    }





    ?>



    registration1-check.inc.php

    <?

    // reset errorstop

    $errorstop = 0;



    if (!$username) {

    $error = "Please enter a username<br>";

    echo $error;

    $errorstop = 1;

    }



    if (!$password1) {

    $error = "Please enter a Password<br>";

    echo $error;

    $errorstop = 1;

    }





    if ($errorstop == 1 ) {

    // show the original form again

    include("includ es/registration1.i nc.php");

    break;

    }

    ?>

    Comment

    Working...