title: Debugging a SQL syntax error in PHP
body: <p>I'm trying to use PDO on my register and log in page , and started working on my register page and have an syntax error not sure why.</p>
  
  <p>The error is below:</p>
  
  <blockquote>
    <p>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 'INSERT INTO users (id, name, username, password, lastname ,email) VALUES (?, ?,' at line 1</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code> if ($_SESSION["username"]){
  
   header("Location: home.php");
   }
  else{
  if(isset($_POST['firstname']) &amp;&amp; isset($_POST['lastname']) &amp;&amp;    isset($_POST['username']) &amp;&amp; isset($_POST['password']) &amp;&amp; isset($_POST['cpassword'])  &amp;&amp; isset($_POST['email'])){
       require('connect.php');
  
       $dusername = mysql_real_escape_string($_POST["username"]);
      $dfirstname = mysql_real_escape_string($_POST["firstname"]);
       $dpassword = md5(mysql_real_escape_string($_POST["password"]));
      $dlastname =mysql_real_escape_string($_POST["lastname"]);
      $demail =mysql_real_escape_string($_POST["email"]);
  
  
  
  
  $dbhost = "xxxxxxx"; 
  $dbname= "xxxxxx";
  $dbuser = "xxxx";
  $mysql_password = "xxxxx";
  
  
  
   try{
  
  
   $db = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.';charset=utf8',   
  
   ''.$dbuser.'',    
  
   ''.$mysql_password.'');
  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  }
  
  catch(PDOException $e){
  echo $e-&gt;getMessage();
  die();
  
  
  }
  
   mysql_error();
    //According to user's input
   $register =mysql_query( "(INSERT INTO users (id, name, username, password, lastname,email)  VALUES (?, ?, ?, ?, ?)")or die(mysql_error());
   $register =$db-&gt;prepare($register);
   $register-&gt;execute(array($dfirstname,$dusername,$dpassword,$dlastname,$demail));
  
  // Check username and password match
  if ($register) {
  // Set username session variable
  $_SESSION['username'] = $_POST['username'];
  // Jump to secured page
  header('Location: home.php');
  exit;
  }
  else{
  
    echo "&lt;div class=\"error\"&gt;Error Signing Up... Make Sure all the require 
  
    fields         are correctly formatted. &lt;/div&gt;";
      }
      }
   else{
  
   }
   }
  </code></pre>
  
  <p>Updated it</p>
  
  <pre><code>  $register ="INSERT INTO users (id, name, username, password, lastname ,email) VALUES('',?, ?, ?, ?, ?)"or die(mysql_error());
    $register =$db-&gt;prepare($register);
    $register-&gt;execute(array('',$dfirstname,$dusername,$dpassword,$dlastname,$demail));
  </code></pre>
  
  <p>Still have the error</p>