title: How to write a prepared insert statement?
body: <p>I'm trying to learn how to write a PDO insert statement, so apologise if the code is not so good, It's coming up with error: </p>
  
  <p>SQLSTATE[42000]: Syntax error or access violation: 1064
  at line 3</p>
  
  <p>But I can't see why it's not working. </p>
  
  <p>Note: I'm trying to pass html input data to a database, and in prepared statement online it says something like this: </p>
  
  <pre><code>$firstname = "John";
  $lastname = "Doe";
  $email = "john@example.com";
  </code></pre>
  
  <p>$variable is relating to the database field name, but how do you reference the name in the html input field? </p>
  
  <p>code can be found here and below: <a href="http://pastebin.com/fjAy1Fvn" rel="nofollow">http://pastebin.com/fjAy1Fvn</a></p>
  
  <pre><code>&lt;?php
  include_once 'dbconnect.php';  
     if(isset($_POST["update_vacancies"])){       
  
      try {
      $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
      // set the PDO error mode to exception
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      // begin the transaction
      $conn-&gt;beginTransaction();
      // our SQL statements
     $conn-&gt;exec("INSERT INTO vacancies (vac_id, vac_post_date, vac_job_title, vac_comp_name, vac_ess_one, vac_ess_two, vac_ess_three, vac_ess_four, vac_ess_five, vac_ess_six, vac_ess_seven, vac_ess_eight, vac_ess_nine, vac_ess_ten,  vac_des_one, vac_des_two, vac_des_three, vac_des_four, vac_des_five, vac_des_six, vac_des_seven, vac_des_eight, vac_des_nine, vac_des_ten, add_info) 
  
     VALUES ('vacData', 'postaDate', 'jobTitle', 'companyNanme', 'vac_ess_one', 'vac_ess_two', 'vac_ess_three', 'vac_ess_four', 'vac_ess_five', 'vac_ess_six', 'vac_ess_seven', 'vac_ess_eight', 'vac_ess_nine', 'vac_ess_ten', ,'vac_des_one' ,'vac_des_two' ,'vac_des_three' ,'vac_des_four' ,'vac_des_five' ,'vac_des_six' ,'vac_des_seven' ,'vac_des_eight' ,'vac_des_nine' ,'vac_des_ten' ,'add_info'  )");
  
  
  // commit the transaction
  $conn-&gt;commit();
  echo "New vacancy created successfully";
  }
  catch(PDOException $e)
  {
  // roll back the transaction if something failed
  $conn-&gt;rollback();
  echo "Error: " . $e-&gt;getMessage();
  }
  }
  
  $conn = null;
  ?&gt;
  </code></pre>
  
  <p>Any help is genuinely appreciated. </p>