1
<?php
if (!isset($_POST['ign'], $_POST['email'])) {
    if($_POST['ign'] && $_POST['email']){
    echo "Please fill out all of the fields!";
        die;
}

if (empty($_POST['ign']) || empty($_POST['email'])) { 
    echo ("Please enter all of the values!"); 
    die;
}

if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $email = $_POST['email'];
    echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");

}

else {
    echo "Your email was invalid!";
    die;
}
?>

I'm getting a syntax error on the last line where ?> is..

Also, just a random side note, can anyone teach me how to insert this into my code?

$valid = (bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']);

is it just

if ($valid == TRUE) {
////////
}

or is declaring that variable already running it?

2
  • possible duplicate of if !isset multiple OR conditions Commented Jan 10, 2012 at 2:29
  • 1
    as a personal preference these are the moment when i consider the advantage of writing the opening and closing braces in the next line so as to assist my eyes in tracing which opening brace(s) is paired to which closing brace. Commented Jan 10, 2012 at 2:37

4 Answers 4

5

You have a missing ending brace } in the first if block.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 You can pretty much assume whenever you get an error on the last line of a file, it is a missing } somewhere. Possibly every time I have seen an error on the last line of a file, it has been a missing }
0

Without following the logic of your script, you have five open braces { and four closed braces }

Comments

0

You open two scopes (with {) around the if (!isset($_POST['ign'], $_POST['email'])) line, so you need to close the dangling one where you need to.

Comments

0

You can take the code from your last question, Validate Email Error , and add a test for length of username and check username is alphanumeric like this:

<?php
if (isset($_POST['ign'], $_POST['email'])) {//do the fields exist
    if($_POST['ign'] && $_POST['email']){ //do the fields contain data
        if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {//is the email address of valid form
            if(ctype_alnum($ign) && ($ign.length > 0) && ($ign.length <= 30)){//is ign alphanumeric and between 1 and 30 characters long
                echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");
            }
            else{
                echo ("Please enter a valid user name!");
            }
        }
        else{
            echo ("Please enter a valid email!");
        }
    }
    else {
        echo ("Please enter all of the values!");
    }
}
else {
    echo ("Error in form data!");
}
?>

Note: If my assumption that $_POST['ign'] is what you meant to say to in the line (bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']) ,is wrong ... post more details on what you need and I'll update my answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.