PHP if.else if statement problem

Discussion in 'PHP' started by sahirfarid, May 1, 2011.

  1. #1
    Dear All,

    Please check the below code and tell me whats the problem with it as I am receiving error message.

    if(isset($_POST['reg'])){
    if($_POST['new']=="new forms"){
    echo'<a href="formpack.zip">Download Form Pack</a><br>';
    echo'<a href="index.html"> Back to Home </a>';

    if($_POST['new']=="New Forms"){
    echo'<a href="formpack.zip">Download Form Pack</a><br>';
    echo'<a href="index.html"> Back to Home </a>';


    } }else{
    echo" We are sorry the code you entered is not correct";
    }
    }

    Regards
    Sahir Farid
     
    sahirfarid, May 1, 2011 IP
  2. x319

    x319 Well-Known Member

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    103
    #2
    There isn't anything wrong, just make sure your posting the "new" field in your form.

    By the way, more readable format and simple code:
    if (isset($_POST['reg'])) {
    	if (strtolower($_POST['new']) == "new forms") {
    		echo '<a href="formpack.zip">Download Form Pack</a><br>';
    		echo '<a href="index.html"> Back to Home </a>';
    	} else {
    		echo "We are sorry the code you entered is not correct"; 
    	}
    }
    PHP:
     
    x319, May 1, 2011 IP
  3. sahirfarid

    sahirfarid Active Member

    Messages:
    240
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Actually I want my form to work with both entries "new forms" as well as "New Forms". It works with "new forms" but not with "New Forms".
     
    sahirfarid, May 1, 2011 IP
  4. Oxyden

    Oxyden Greenhorn

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    The code that x319 should resolve this issue because he is converting the whole string to lower case. Have you tried using it?
     
    Oxyden, May 2, 2011 IP
  5. sahirfarid

    sahirfarid Active Member

    Messages:
    240
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    Whats the difference between both codes, as both are same but first one is working and second one is not working properly i-e, executing both statements before and after "else"


    ##This one is working


    if(isset($_POST['reg'])){
    if (strtolower($_POST['new'])=="new forms"){
    echo'<a href="formpack.zip">Download Form Pack</a><br>';
    echo'<a href="index.html"> Back to Home </a>';


    } }else{
    echo" We are sorry the code you entered is not correct";

    }

    ##AND
    ##This one is showing error

    if(isset($_POST['addform'])){

    if (strtolower($_POST['loc'])== "update forms"){

    echo'<a href="Locationch.pdf">Download Location Form</a><br>';
    echo'<a href="index.html"> Back to Home </a>';
    }else{
    echo" We are sorry the code you entered is not correct";

    }




    }
     
    sahirfarid, May 2, 2011 IP
  6. salmanshafiq

    salmanshafiq Well-Known Member

    Messages:
    260
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #6
    sahirfarid has posted the correct code...
     
    salmanshafiq, May 2, 2011 IP
  7. x319

    x319 Well-Known Member

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    103
    #7
    What is the error your getting?
     
    x319, May 2, 2011 IP
  8. sahirfarid

    sahirfarid Active Member

    Messages:
    240
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    There was a closing bracket issue, I've solved it. Thanks everyone who helped me to solve it. :)
     
    sahirfarid, May 2, 2011 IP