PHP If Statement Help!

Status
Not open for further replies.

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello all,

I am trying to make form with a few checks...

I have it all in an if statement so variable text doesn't show before the submit button has been pressed.
I know it seems this code is useless but it won't be after I fully develop it.
I am trying to set it up to check to see if a check box is checked, which it always is but this part is just for the submit button.
Then it checks to see if the following variables are empty; $username, $email & $dob
Then it checks if the terms & conditions have been accepted; $tc.
The only problem I have is, the IF statement for the empty variables doesn't run, if I leave text boxes empty it just runs straight to "You must accept the terms & conditions."

EDIT: I REALISE I AM MISSING DOUBLE AMPERSANDS BUT IT STILL DOESN'T WORK!

Can anybody help with this?

Code:
PHP:
if($accept == "Yes"){
                if($username == "" & $dob == "" & $email == ""){
                echo "Looks like you missed something...";
            }
                else if($tc == "checked"){
                    #Accept code goes here!
                    echo "Username  = " . $username . "<br />";
                    echo "Date of Birth = " . $dob . "<br />";
                    echo "Email = " . $email . "<br />";
                    echo "Credit's = " . $credits . "<br />";
                    echo "Approval ticket = " . $ticket;
                }
                        else{
                                echo "You must accept the terms & conditions!";
                        }
        }
        else{
            #Do not accept code goes here!
            echo "<form action='random.php' method='post'>
        <!-- Form code goes in here -->
        <label for='username'>Username: </label><br /><input type='text' name='username'> <br />
        <label for='email'>E-Mail: </label><br /><input type='text' name='email'> <br />
        <label for='dob'>Date of Birth: </label><br /><input type='text' name='dob'><br />
        <label for='tac'>I accept the Terms & conditions : </label><input name='tac' type='checkbox' value='checked'>
        <input name='accept' value='Yes' type='checkbox' checked='checked' style='display:none;'>
        <input type='submit' value='Submit!'>
    </form>";
        }
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,484
1,486
PHP:
<?php
if($accept == "Yes"){
                if($username == "" & $dob == "" & $email == ""){
                echo "Looks like you missed something...";
            }
                else if($tc == "checked"){
                    //Accept code goes here!
                    echo "Username  = " . $username . "<br />";
                    echo "Date of Birth = " . $dob . "<br />";
                    echo "Email = " . $email . "<br />";
                    echo "Credit's = " . $credits . "<br />";
                    echo "Approval ticket = " . $ticket;
                }
                        else{
                                echo "You must accept the terms & conditions!";
                        }
        }
        else{
?>
<form action='random.php' method='post'>
        <!-- Form code goes in here -->
        <label for='username'>Username: </label><br /><input type='text' name='username'> <br />
        <label for='email'>E-Mail: </label><br /><input type='text' name='email'> <br />
        <label for='dob'>Date of Birth: </label><br /><input type='text' name='dob'><br />
        <label for='tac'>I accept the Terms & conditions : </label><input name='tac' type='checkbox' value='checked'>
        <input name='accept' value='Yes' type='checkbox' checked='checked' style='display:none;'>
        <input type='submit' value='Submit!'>
</form>
<?php } ?>

Instead of altering, I just did a simple way. 
PHP:
 else{
                                echo "You must accept the terms & conditions!";
                        }
        }  <-- What is this one closing?
        else{

That is closing

PHP:
if($accept == "Yes"){
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Still when entering no text in the text boxes, it asks for the terms & conditions instead of displaying the "Something is missing" text.

You can see for yourself here:
 
Status
Not open for further replies.

Users who are viewing this thread

Top