title: Validation and database connectivity for a html page using MySql and PHP
body: <p>This is my code to create a simple login page having Username, Password, confirm password and a identify yourself <code>select</code>option:- </p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Sign up&lt;/title&gt;
  &lt;style type="text/css"&gt;
      div#registration
      {
          text-align:center;
          margin-left:auto;
          margin-right:auto;
          width:40%;
          border:solid 2px green;
      }
  &lt;/style&gt;
  
  &lt;/head&gt;
  
  
  
  &lt;body&gt;
  &lt;h1&gt; Sign Up! &lt;/h1&gt;
  &lt;h2&gt; Enter username and password. Dont forget to recognize yourself &lt;/h2&gt;
  
  &lt;?php
  
          $mysqli = new mysqli("localhost", "root", "", "signup");
          if($mysqli===false)
          {
              die("ERROR: Could not connect to database." .mysqli_connect_error());
          }
  
          if(isset($_POST['submit']))
          {
  
  
              echo'&lt;div id="message"&gt;';
  
              $inputError = false;
              if(empty($_POST['username'] ))
              {
                  echo 'ERROR: Please enter a valid user name';
                  $inputError = true;
              }
              else
              {
                  $username= $mysqli-&gt;escape_string($_POST['username']);
              }
  
  
              if($inputError != true &amp;&amp; empty($_POST['password'] ))
              {
                  echo 'ERROR: Please enter valid password';
                  $inputError = true;
              }
              else
              {
                  $password= $mysqli-&gt;escape_string($_POST['password']);
              }
  
  
              $inputError = false;
              if(empty($_POST['cfmpassword'] ))
              {
                  echo 'ERROR: empty field';
                  $inputError = true;
              }
              else if($_POST['password'] != $_POST['cfmpassword'])
              {
                  echo 'ERROR: passwords does not match';
              }
              else
              {
                  $cfmpassword = $mysqli-&gt;escape_string($_POST['cfmpassword']);
              }
  
  
          if($inputError != true &amp;&amp; empty($_POST['desig'] ))
          {
              echo 'ERROR: Please enter valid password ';
              $inputError = true;
          }
          else
          {
              $desig= $mysqli-&gt;escape_string($_POST['desig']);
          }
  
          if ($inputError !=true)
          {
                  $sql= "INSERT INTO database (Username, password, confirm password, Designation) VALUES ('$username','$password','$cfmpassword','$desig')";
  
                  if ($mysqli-&gt;query($sql) === true)
                  {
                      echo 'new record added with ID:' . $mysqli-&gt;insert_id;
                  }
                  else
                  {
                      echo "ERROR: Could not execute query: $sql." .$mysqli-&gt;error;
                  }
          }
          echo '&lt;/div&gt;';
  
          $mysqli-&gt;close();
      }
  ?&gt;
  
  &lt;form action="signup.php" method="post"&gt;
  
  Username:
  &lt;input type="text" size="20" name="username" /&gt;
  &lt;p/&gt;
  
  Password:
  &lt;input type="password" size="20" name="password" /&gt;
  &lt;p/&gt;
  
  Confirm Password:
  &lt;input type="password" size="20" name="cfmpassword" /&gt;
  &lt;p/&gt;
  
  Identify yourselves:
  &lt;select name="desig"&gt;
  
  &lt;option name="admin"&gt;Admin&lt;/option&gt;
  &lt;option name="Faculty"&gt;Faculty&lt;/option&gt;
  &lt;option name="Student"&gt;Student&lt;/option&gt;
  &lt;/select&gt;
  &lt;p/&gt;
  
  &lt;input type="submit" name="submit" value="Submit" /&gt;
  
  &lt;/form&gt;
  
  
  
  
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my updated code, The validations are working completely fine now but I'm getting an error.This is the error which i'm getting. What is the possible mistake in this code? </p>
  
  <pre><code>ERROR: Could not execute query: INSERT INTO database (Username, password, confirm password, Designation) VALUES ('suhas','99','99','Admin').You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database (Username, password, confirm password, Designation) VALUES ('suhas','99' at line 1
  </code></pre>