title: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
body: <p>Exact Error: </p>
  
  <blockquote>
    <p>SQLSTATE[42000]: Syntax error or access violation: 1064 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 '' at line 20</p>
  </blockquote>
  
  <p>I'm completely new to SQL and PHP, so as part of an assignment I was asked to edit a mentor's code and insert into my project. However, when I run the code, it comes up with an SQL syntax error at line 20 (which is where the <code>&lt;body&gt;</code> tag opens). Could someone please help me pinpoint the error? I'm really new to this stuff, and I'm sorry in advance if this is seen as "rude" or if I'm wasting your time &lt;3.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;"Sign Up" Form:&lt;/title&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt;
  
      &lt;!-- Latest compiled and minified CSS --&gt;
  &lt;!-- Latest compiled and minified CSS --&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"&gt;
  
  &lt;!-- Optional theme --&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"&gt;
  
  &lt;!-- Latest compiled and minified JavaScript --&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="page-wrapper"&gt;
          &lt;div class="wrapper style1"&gt;
              &lt;section id="main" class="container"&gt;
  
                  &lt;?php
                      //-------------------------------------------------
                      $firstNameVal = 'Insert First Name';
                      $lastNameVal = 'Insert Surname';
                      $usernameVal = 'Choose a Username';
                      $passwordVal = '-------';
                      $emaiAddresslVal = 'Insert email';
                      $addressVal = 'Insert Address';
                      $suburbVal = 'Insert Suburb';
                      $ageVal = '17';
  
                      //-------------------------------------------------
  
  
  
                      //database credentials
                      define('DBHOST','localhost');
                      define('DBUSER','root');
                      define('DBPASS','root');
                      define('DBNAME','Login');
  
                      //new database connection
                      $db = new PDO("mysql:host=".DBHOST.";port=3306;dbname=".DBNAME, DBUSER, DBPASS);
                      $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
                      //if form has been submitted process it
                      if(isset($_POST['submit'])){
                          // ???
                          $_POST = array_map( 'stripslashes', $_POST );
  
                          //collect form data
                          extract($_POST);
  
                          //very basic validation
                          if($firstName ==''){
                              $error[] = 'Please enter a first name.';
                          }
                          if($lastName ==''){
                              $error[] = 'Please enter a last name.';
                          }
  
                          if($username ==''){
                              $error[] = "Please enter a username";
                          }
                          if($password ==''){
                              $error[] = 'Please enter a password';
                          }
                          if($emailAddress ==''){
                              $error[] = 'Please enter an email address.';
                          }
                          if($address ==''){
                              $error[] = "Please enter your address";
                          }
                          if($suburb ==''){
                              $error[] = 'Please enter your suburb.';
                          }
                          if($mobile ==''){
                              $error[] = 'Please enter your personal mobile  number.';
                          }
                          if($age == ''){
                              $error[] = 'Please enter your age!';
                          }
                          if(!isset($error)){
  
                              try {
  
                                  //insert into database
                                  $query = $db-&gt;prepare('INSERT INTO user(
                                  firstName, 
                                  lastName, 
                                  username,
                                  password,
                                  emailAddress,
                                  address,
                                  suburb,
                                  age,
                                  mobile) 
                                  VALUES (
                                  :firstName, 
                                  :lastName, 
                                  :username, 
                                  :password, 
                                  :emailAddress, 
                                  :address, 
                                  :suburb, 
                                  :age, 
                                  :mobile, 
                                  ');
                                  $query-&gt;execute(array(
                                      ':firstName' =&gt; $firstName, // processes the values for each form field
                                      ':lastName' =&gt; $lastName, //
                                      ':username' =&gt; $username, //
                                      ':password' =&gt; $password, //
                                      ':emailAddress' =&gt; $emailAddress, //
                                      ':address' =&gt; $address, //
                                      ':suburb' =&gt; $suburb, //
                                      ':age' =&gt; $age, //
                                      ':mobile' =&gt; $mobile, //
                                  ));
  
                                  //redirect to index page
                                  header('Location: success.php');
                                  exit;
                                  // if error, it displays error
                              } catch(PDOException $e) {
                                  echo $e-&gt;getMessage();
                              }
                          }
                      }
                      //check for any errors
                      if(isset($error)){
                          echo '&lt;section id="content" class="box" style="background-color: #F4CDCD;"&gt;';
                              echo '&lt;h3&gt;Errors&lt;/h3&gt;';
                              echo '&lt;b&gt;&lt;ul&gt;';
                              foreach($error as $error){
                                  echo '&lt;li&gt;'.$error.'&lt;/li&gt;';
                              }
                              echo '&lt;/ul&gt;&lt;/b&gt;';
                          echo '&lt;/section&gt;';
                      }
                  ?&gt;
  
                      &lt;form method="post"&gt;
  
                          &lt;!-- Your Details --&gt;
                          &lt;section id="content" class="box"&gt;
                              &lt;h3&gt;Your Details&lt;/h3&gt;
                              &lt;div class="row uniform 60%"&gt;
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="firstName"&gt;First Name&lt;/label&gt;
                                      &lt;input type="text" name="firstName" id="firstName" value="&lt;?php if(isset($error)){ echo $_POST['firstName'];}?&gt;" placeholder="First Name" /&gt;
                                  &lt;/div&gt;
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="lastName"&gt;Last Name&lt;/label&gt;
                                      &lt;input type="text" name="lastName" id="lastName" value="&lt;?php if(isset($error)){ echo $_POST['lastName'];}?&gt;" placeholder="Last Name" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="row uniform 60%"&gt;
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="username"&gt;username&lt;/label&gt;
                                      &lt;input type="text" name="username" id="username" value="&lt;?php if(isset($error)){ echo $_POST['username'];}?&gt;" placeholder="Userame" /&gt;
                                  &lt;/div&gt; 
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="password"&gt;password&lt;/label&gt;
                                      &lt;input type="password" name="password" id="password" value="&lt;?php if(isset($error)){ echo $_POST['password'];}?&gt;" placeholder="Password" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row uniform 60%"&gt;
  
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="emailAddress"&gt;Email&lt;/label&gt;
                                      &lt;input type="email" name="emailAddress" id="emailAddress" value="&lt;?php if(isset($error)){ echo $_POST['emailAddress'];}?&gt;" placeholder="jane.doe@compuhyperglobalmeganet.com" /&gt;
                                  &lt;/div&gt;
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="mobile"&gt;Mobile&lt;/label&gt;
                                      &lt;input type="text" name="mobile" id="mobile" value="&lt;?php if(isset($error)){ echo $_POST['mobile'];}?&gt;" placeholder="1234 567 890" /&gt;
                                  &lt;/div&gt;
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="age"&gt;Age&lt;/label&gt;
                                      &lt;input type="text" name="age" id="age" value="&lt;?php if(isset($error)){ echo $_POST['age'];}?&gt;" placeholder="17" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row uniform 60%"&gt;
  
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="address"&gt;Address&lt;/label&gt;
                                      &lt;input type="text" name="address" id="address" value="&lt;?php if(isset($error)){ echo $_POST['Address'];}?&gt;" placeholder="21B Baker Street" /&gt;
                                  &lt;/div&gt;
                                  &lt;div class="6u 12u(narrower)"&gt;
                                      &lt;label for="suburb"&gt;Mobile&lt;/label&gt;
                                      &lt;input type="text" name="suburb" id="suburb" value="&lt;?php if(isset($error)){ echo $_POST['suburb'];}?&gt;" placeholder="marylebone" /&gt;
                                  &lt;/div&gt;
  
                              &lt;/div&gt;
                          &lt;/section&gt;
  
                          &lt;br&gt;
                          &lt;!-- Submit Button --&gt;
                          &lt;section id="content" class="box"&gt;
                              &lt;div class="row uniform 60%"&gt;
                                  &lt;div class="12u"&gt;
                                      &lt;ul class="actions"&gt;
                                          &lt;li style="width: 100%; list-style: none; "&gt;
                                              &lt;input type="submit" name="submit" value="Finish and Submit" style="width: 100%;" /&gt;
                                          &lt;/li&gt;
                                      &lt;/ul&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/section&gt;
  
                      &lt;/form&gt;
  
              &lt;/section&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;!-- Scripts --&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>