1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can I stop an if else statement if something is false?

Discussion in 'PHP' started by Maig, May 1, 2007.

  1. #1
    I am new to programming and I have a form that I am trying to make. I would like to have the password validate and if it does not, then the script should stop. I have the instructions in an if else statement and I can't seem to use 'break' to make it stop. Is there a way to do this?

    Here is the code:

    if(isset($_POST["number"])){
    if(!($_POST["number"])){
    echo "Please type a password";
    }
    else if (($_POST["number"]) != ("W34Ut8")){
    echo "Invalid password, sorry";
    }
    else {
    echo "Password accepted";
    }
    }​


    There is more code after this section that continues to "POST" the information from the form, however, I want the script to STOP and display the "statement" if there is no password or if the password is invalid.

    Can I do that with this code I have written?
     
    Maig, May 1, 2007 IP
  2. sky22

    sky22 Guest

    Messages:
    59
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you want to completely stop and exit the script you can use die( 'statment' ) or exit()
     
    sky22, May 1, 2007 IP
  3. Maig

    Maig Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Oh, THANK YOU so much, the exit() worked just the way I had hoped.

    Maig.
     
    Maig, May 1, 2007 IP