Jump to content

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


kaizer

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.