PHP Statement Issue

Status
Not open for further replies.

Kristo

Website & Software Developer
Feb 5, 2015
269
69
I am very new to PHP coding and am having some problems with a simple bit of code and was looking for some help. It says I have 'Unexpected T_EMPTY'

PHP:
<?php

if(empty($_POST['submit']))
{
    echo "Form is not submitted!";
    exit;
}
if(empty($_POST["fullname"]) ||
    empty($_POST["email"])
    empty($_POST["tel"])
    empty($_POST["message"]))
        {
            echo "Please fill the form";
            exit;
        }
       
        $name = $_POST["fullname"];
        $email = $_POST["email"];
        $tel = $_POST["tel"];
        $message = $_POST["message"];

mail( '[email protected]' , 'Contact Form Submission' ,
"New form submission: Name: $name, Email: $email, Telephone: $tel, Message: $message"   );

header('Location: thank-you.html');
?>
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
I am very new to PHP coding and am having some problems with a simple bit of code and was looking for some help. It says I have 'Unexpected T_EMPTY'

PHP:
<?php

if(empty($_POST['submit']))
{
    echo "Form is not submitted!";
    exit;
}
if(empty($_POST["fullname"]) ||
   empty($_POST["email"])
   empty($_POST["tel"])
    empty($_POST["message"]))
        {
            echo "Please fill the form";
            exit;
        }
 
        $name = $_POST["fullname"];
        $email = $_POST["email"];
        $tel = $_POST["tel"];
        $message = $_POST["message"];

mail( '[email protected]' , 'Contact Form Submission' ,
"New form submission: Name: $name, Email: $email, Telephone: $tel, Message: $message"   );

header('Location: thank-you.html');
?>
It's because you're missing two OR operators
PHP:
if (empty($_POST["fullname"]) ||
    empty($_POST["email"])
    empty($_POST["tel"])
    empty($_POST["message"]))
Needs to be:
PHP:
if (empty($_POST["fullname"]) ||
    empty($_POST["email"]) || // || <= was missing
    empty($_POST["tel"]) || // || <= was missing
    empty($_POST["message"]))

Please set this as the best answer :)
 
Status
Not open for further replies.

Users who are viewing this thread

Top