-1

I'm writing a simple php validation code for a project I'm doing and I'm having it validate first name, last name, and email. I got this error and ive looked over it for atleast 45 mins and can't figure out what it is.

<?php
 $fnameErr = $lnameErr = $emailErr = "";
 $firstname = $lastname = $email = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
 if (empty($_POST["firstname"])) {
 $fnameErr = "First name is required";
}

This is line 38-46

4 Answers4

1

Looks like one of the braces haven't been closed.

<?php
    $fnameErr = $lnameErr = $emailErr = "";
    $firstname = $lastname = $email = "";

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (empty($_POST["firstname"])) {
            $fnameErr = "First name is required";
        }
    } // Add an ending brace
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
1

You have missed end your second if condition. code should be like this.

 if ($_SERVER["REQUEST_METHOD"] == "POST") {
     if (empty($_POST["firstname"])) {
        $fnameErr = "First name is required";
     }
 }//this } symbol you have missed.
Vimukthi Guruge
  • 285
  • 3
  • 15
1

you missed your second condition bracket and you can update your code which will more readable

<?php
 // this is error variable
 $fnameErr = "";
 $lnameErr = "";
 $emailErr = "";

// this is post initial variable define
 $firstname = "";
 $lastname = "";
 $email = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["firstname"])) {
    $fnameErr = "First name is required";
  }
}
?>

for more information

PHP Parse/Syntax Errors; and How to solve them?

Community
  • 1
  • 1
Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43
0

Use IDE to help you with syntax errors. I think you are in a learning stage, so I would suggest you to use an IDE (Eclipse or Netbeans)

Missing braces:

 $fnameErr = $lnameErr = $emailErr = "";
 $firstname = $lastname = $email = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
 if (empty($_POST["firstname"])) {
 $fnameErr = "First name is required";
}
}//Here
Harikrishnan N
  • 874
  • 1
  • 10
  • 19