title: Undefined index:firstname,lastname,email,phone in line83
body: <p>I am having problem in this following code.It says undefined index on line 83.The second problem is that there is a huge gap between the text  fill the required form and the input textbox of the form during output.Please help me out.The code is posted below.</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;style&gt;
              .error {color: #FF0000;}
          &lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;?php
              $firstnameErr = $lastnameErr = $emailErr = "";
              $firstname = $lastname = $email = "";
  
              if ($_SERVER["REQUEST_METHOD"] == "POST")
              {
                  if (empty($_POST["firstname"]))
                  {
                      $firstnameErr = "Name is required";
                  }
                  else
                  {
                      $firstname = test_input($_POST["firstname"]);
                  }
  
                  if (empty($_POST["lastname"]))
                  {
                      $lastnameErr = "Name is required";
                  }
                  else
                  {
                      $lastname = test_input($_POST["lastname"]);
                  }
                  if (empty($_POST["email"]))
                  {
                      $emailErr = "Email is required";
                  }
                  else
                  {
                      $email = test_input($_POST["email"]);
                  }
              }
  
              function test_input($data)
              {
                  $data = trim($data);
                  $data = stripslashes($data);
                  $data = htmlspecialchars($data);
                  return $data;
              }         
          ?&gt;
          &lt;div text align =center&gt;&lt;h1&gt;Eventous Info&lt;/h1&gt;&lt;/div&gt;
          &lt;h3&gt;Fill the Required Form:&lt;/h3&gt;
          &lt;p&gt;&lt;span class="error"&gt;*required field&lt;/span&gt;&lt;/p&gt;
          &lt;table&gt;
              &lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt; 
                  &lt;tr&gt;&lt;?php// echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;
                      &lt;td&gt;Firstname:&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="firstname" &gt;&lt;/td&gt;
                      &lt;td&gt;&lt;span class="error"&gt;* &lt;?php echo $firstnameErr;?&gt;&lt;/span&gt;&lt;/td&gt;&lt;br&gt;&lt;br&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Lastname:&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="lastname" &gt;&lt;/td&gt;
                      &lt;td&gt;&lt;span class="error"&gt;* &lt;?php echo $lastnameErr;?&gt;&lt;/span&gt;&lt;/td&gt;&lt;br&gt;&lt;br&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Email&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="email"&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;span class="error"&gt;* &lt;?php echo $emailErr;?&gt;&lt;/span&gt;&lt;/td&gt;&lt;br&gt;&lt;br&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Phone:&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="number"&gt;&lt;td&gt;&lt;br&gt;&lt;br&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;input type="submit" &gt;
          &lt;/form&gt;
  
          &lt;?php
              $con = mysql_connect("localhost","ashu123","bangalore");
              if (!$con)
              {
                  die('Could not connect: ' . mysql_error());
              }
              mysql_select_db("evantus", $con);
  
              $sql="INSERT INTO employee (firstname, lastname, email, phone )
                ***LINE-83***
              VALUES
              ('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[number]')";
  
              $sql = "select * from employee";
              $query = mysql_query( $sql );
  
  
              echo "&lt;table&gt;";
              echo "&lt;tr&gt;&lt;th&gt;firstname&lt;/th&gt;";
  
              echo "&lt;th&gt;lastname&lt;/th&gt;";
  
              echo "&lt;th&gt;email&lt;/th&gt;";
  
              echo "&lt;th&gt;phone&lt;/th&gt;&lt;/tr&gt;";
              while( $row = mysql_fetch_assoc($query) )
              {
                  echo "&lt;tr&gt;&lt;td&gt;$row[firstname]&lt;/td&gt;";
                  echo "&lt;td&gt;$row[lastname]&lt;/td&gt;";
                  echo "&lt;td&gt;$row[email]&lt;/td&gt;";
                  echo "&lt;td&gt;$row[phone]&lt;/td&gt;&lt;/tr&gt;";
              }
  
              echo "&lt;/table&gt;";
  
              if (!mysql_query($sql,$con))
              {
                  die('Error: ' . mysql_error());
              }
              mysql_close($con)
          ?&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>