Jump to content

I am getting the following error:Parse error: parse error, unexpected T_Etc..


Recommended Posts

error message:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in C:\Apache2\htdocs\inputvalidation.php on line 19

 

this is an example I am using to learn PHP and I am getting the above error as a result of running this example. could you please tell me why I am getting this error.

 

input validation code:

<?php

if (isset($_POST["submit"'])) {

$firstname = $_POST["firstname"];

$lastname = $_POST["lastname"];

if (!empty($firstname) && !empty($lastname)) {

Header("Location: inputsuccess.php");

}

else {$error = true;}

}

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>This is (Recursive) Input Validation</title>

</head>

<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<?php

if ( $error && empty($firstname) ) {

echo '<span style="color:red">';

echo "Error! Please enter a first name.</span><br />";

}

?>

First name:

<input name="firstname" type="text" value="<?php echo $firstname; ?>" />

<br />

<?php

if ($error && empty($lastname)) {

echo '<span style="color:red">';

echo "Error! Please enter a last name.</span><br />";

}

?>

Last name:

<input name="lastname" type="text" value="<?php echo $lastname; ?>" />

<br />

<br />

<input type="submit" name="submit" value="Submit" />

</form>

</body>

</html>

 

 

if (isset($_POST["submit"'])) {

 

Removed the extra single quote, try this.

 

<?php

   if (isset($_POST["submit"])) {
      $firstname = $_POST["firstname"];
      $lastname = $_POST["lastname"];
      if (!empty($firstname) && !empty($lastname)) {
      Header("Location: inputsuccess.php");
   }
   else {$error = true;}
   }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>This is (Recursive) Input Validation</title>
   </head>
   <body>
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <?php
         if ( $error && empty($firstname) ) {
            echo '<span style="color:red">';
            echo "Error! Please enter a first name.</span>
";
         }
      ?>
         First name:
         <input name="firstname" type="text" value="<?php echo $firstname; ?>" />
            

            <?php
            if ($error && empty($lastname)) {
               echo '<span style="color:red">';
               echo "Error! Please enter a last name.</span>
";
            }
      ?>
      Last name:
         <input name="lastname" type="text" value="<?php echo $lastname; ?>" />
         

         

         <input type="submit" name="submit" value="Submit" />
         </form>
   </body>
</html>

 

--FrosT

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.