Depetrify
Depetrify

Reputation: 175

PHP Syntax Error on Last Line?

<?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?

Upvotes: 1

Views: 2032

Answers (4)

vdbuilder
vdbuilder

Reputation: 12994

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.

Upvotes: 0

slugonamission
slugonamission

Reputation: 9642

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.

Upvotes: 0

al01
al01

Reputation: 122

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

Upvotes: 0

FtDRbwLXw6
FtDRbwLXw6

Reputation: 28929

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

Upvotes: 5

Related Questions