title: SQLSTATE[42000]: Syntax error or access violation: 1064, can't find source
body: <p>I'm being thrown an 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 '* FROM auction
    WHERE etime &lt; ?' at line 1 "</p>
  </blockquote>
  
  <p>My understanding of this is usually I have spelt something wrong where it says the error is occurring. </p>
  
  <p>However, in the following script, there is no <code>"* FROM auction WHERE etime &lt; ?"</code> on line 1 of my page. </p>
  
  <p>Further it occurs only 3 times in the page - at line 19, 26 and 288. </p>
  
  <p>I've checked all these locations for a syntax blunder around it and it looks proper. So I have no idea why this is being thrown, I want it to go away. </p>
  
  <p>The page is rather large, bear with me: </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;?php
  
  session_start();
  $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  $_SESSION['lasturl'] = $url;
  
  include("connect.php");
  
  $pdo = connect();
  $pdo-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  
      try{
          $old = time() - (60*24*60*60);
          $stmt15 = $pdo-&gt;prepare("DELETE * FROM auction WHERE etime &lt; :time");
          $stmt15-&gt;bindParam(":time", $old, PDO::PARAM_INT);
          $stmt15-&gt;execute();
  
          $time = time();
  
          $stmt8 = $pdo-&gt;prepare("SELECT * FROM auction WHERE etime &lt; :time AND closed &lt; 1");
          $stmt8-&gt;bindParam(":time", $time, PDO::PARAM_INT);
          $stmt8-&gt;execute();
  
          while($row = $stmt8-&gt;fetch(PDO::FETCH_ASSOC)){
              $id = $row['ID'];
              $holder = $row['holder'];
              $owner = $row['owner'];
  
              $stmt5 = $pdo-&gt;prepare("UPDATE auction SET closed = 50 WHERE ID = :id");
              $stmt5-&gt;bindParam(":id", $id, PDO::PARAM_INT);
              $stmt5-&gt;execute();
  
              $stmt3 = $pdo-&gt;prepare("SELECT * FROM user WHERE username = :holder");
              $stmt3-&gt;bindParam(":holder", $holder, PDO::PARAM_STR);
              $stmt3-&gt;execute();
  
              $row2 = $stmt3-&gt;fetch(PDO::FETCH_ASSOC);
              $fbtokenh = $row2['fbtoken'];
  
              $fbtokenh++;
  
              $stmt4 = $pdo-&gt;prepare("UPDATE user WHERE username = :holder SET fbtoken = :fbtoken");
              $stmt4-&gt;bindParam(":holder", $holder, PDO::PARMA_STR);
              $stmt4-&gt;bindParam(":fbtoken", $fbtokenh, PDO::PARAM_INT);
              $stmt4-&gt;execute();
  
              $stmt6 = $pdo-&gt;prepare("SELECT * FROM user WHERE username = :owner");
              $stmt6-&gt;bindParam(":owner", $owner, PDO::PARAM_STR);
              $stmt6-&gt;execute();
  
              $row3 = $stmt6-&gt;fetch(PDO::FETCH_ASSOC);
              $fbtokeno = $row2['fbtoken'];
  
              $fbtokeno++;
  
              $stmt7 = $pdo-&gt;prepare("UPDATE user WHERE username = :owner SET fbtoken = :fbtoken");
              $stmt7-&gt;bindParam(":owner", $owner, PDO::PARAM_STR);
              $stmt7-&gt;bindParam(":fbtoken", $fbtokeno, PDO::PARAM_INT);
              $stmt7-&gt;execute();
  
          }
      }catch(PDOException $e){
          echo $e-&gt;getMessage();
  }
  
  if(isset($_GET['searchbox'])){
      $search = $_GET['searchbox'];
  }
  ?&gt;
  
  
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Trade diving equipment online at DiveBay&lt;/title&gt;
  
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" type="text/css" href="js/jquery.countdown.css" /&gt;
  &lt;script type="text/javascript" src="js/jquery.countdown.js"&gt;&lt;/script&gt;
  &lt;script src="js/menuscript.js" language="javascript" type="text/javascript"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/menustyle.css" media="screen, print" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/searching.css" /&gt;
  
  
  
  
  
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;center&gt;
      &lt;div id="wrapper"&gt;
  
          &lt;div id="header"&gt;
              &lt;div id="hbackground"&gt;
                  &lt;img src="db3.jpg" alt="hbackground" width="100%" height="100%" style="z-index:1;" /&gt;
                  &lt;div id="htitle"&gt;
                      &lt;span id="banner"&gt;DIVEBAY.COM&lt;/span&gt;
                      &lt;span id="byline"&gt;SEARCHING FOR STUFF ONLINE&lt;/span&gt;
  
                      &lt;table border="0" cellpadding="0" cellspacing="0" style="float:right; background-color:transparent;"&gt;
                          &lt;tr&gt;
                              &lt;td&gt;
                                  &lt;a href="search.php" onmouseover="setOverImg('1','');" onmouseout="setOutImg('1','');" target=""&gt;&lt;img src="buttons/button1up.png" border="0" id="button1" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
                                  &lt;a href="sellanitem.php" onmouseover="setOverImg('2','');" onmouseout="setOutImg('2','');" target=""&gt;&lt;img src="buttons/button2up.png" border="0" id="button2" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
                                  &lt;a href="forum.php" onmouseover="setOverImg('3','');" onmouseout="setOutImg('3','');" target=""&gt;&lt;img src="buttons/button3up.png" border="0" id="button3" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
                                  &lt;a href="myaccount.php" onmouseover="setOverImg('4','');" onmouseout="setOutImg('4','');" target=""&gt;&lt;img src="buttons/button4up.png" border="0" id="button4" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
                                  &lt;a href="support.php" onmouseover="setOverImg('5','');" onmouseout="setOutImg('5','');" target=""&gt;&lt;img src="buttons/button5up.png" border="0" id="button5" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
  &lt;?php
  if(isset($_SESSION['loggedin'])){
  ?&gt;
                                  &lt;a href="logout.php" onmouseover="setOverImg('7','');" onmouseout="setOutImg('7','');" target=""&gt;&lt;img src="buttons/button7up.png" border="0" id="button7" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
  &lt;?php
  }else{
  ?&gt;
                                  &lt;a href="login_to_divebay.php" onmouseover="setOverImg('6','');" onmouseout="setOutImg('6','');" target=""&gt;&lt;img src="buttons/button6up.png" border="0" id="button6" vspace="1" hspace="1"&gt;&lt;/a&gt;&lt;br&gt;
  &lt;?php
  }
  ?&gt;
  
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
  
  
  
  
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
  
          &lt;div id="searchandlog"&gt;
              &lt;div id="search"&gt;
                  &lt;form id="searchdivebay" action="search.php" method="get"&gt;
                      &lt;div id="searchboxholder"&gt;&lt;input type="text" name="searchbox" id="searchbox" /&gt;&lt;/div&gt;
                      &lt;div id="searchbuttonholder"&gt;&lt;input type="submit" name="searchbutton" id="searchbutton" value="Search DiveBay"/&gt;&lt;/div&gt;
                      &lt;input type="hidden" id="submit" name="submit" value="1"/&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
              &lt;div id="login"&gt;
  &lt;?php
  if(isset($_SESSION['loggedin'])){
      echo '&lt;span class="price1"&gt;Logged in as:&lt;/span&gt;&amp;nbsp;&lt;span class="sessionset"&gt;'.$_SESSION['username'].'&lt;/span&gt;';
  }
  else{
      echo '&lt;ul class="signreg"&gt;
              &lt;li&gt;&lt;i&gt;Existing user?&lt;/i&gt;&lt;a href="login_to_divebay.php"&gt;SIGN IN&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;i&gt;or, new?&lt;/i&gt;&lt;a href="createacct.php"&gt;REGISTER&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;';
  }               
  ?&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
  &lt;?php
  if(isset($_POST['searchbox'])){
  
  if($search == ""){
  ?&gt;
      &lt;p style="color:black; font-size:18pt; font-family: Impact; "&gt; You didn"t search for anything!&lt;/p&gt;
  &lt;?php
  }else{
  try{
      $time = time();
      $stmt12 = $pdo-&gt;prepare('SELECT * FROM auction WHERE name LIKE :name');
      $stmt12-&gt;bindParam(':name', '%'. trim($search) .'%',PDO::PARAM_STR);
  
      $stmt12-&gt;execute();
  
  
  
      $numrows = 0;
  ?&gt;
  
          &lt;div id="searchresults"&gt;&lt;span style="font-style:italic; font-size: 14pt; font-family:Impact;"&gt;Search results for: &lt;/span&gt;&amp;nbsp&lt;span id="searchword"&gt;&lt;?php echo $search; ?&gt;&lt;/span&gt;&lt;/div&gt;
          &lt;div id="content"&gt;
          &lt;table id="displaying" class="displayer"&gt;
  &lt;?php
  
  while($row = $stmt12-&gt;fetch(PDO::FETCH_ASSOC)){
          $numrows++;
          $ID = $row['ID'];
          $img = $row['img'];
          $desc = $row['description'];
          $name = $row['name'];
          $owner = $row['owner'];
          $cprice = $row['sprice'];
          $iprice = $row['iprice'];
          $incprice = $row['incprice'];
          $etime = $row['etime'];
          $nextBid = $cprice + $incprice;
  
  $stmt21 = $pdo-&gt;prepare("SELECT * FROM user WHERE username = :username");
  $stmt21-&gt;bindParam(":username", $owner,PDO::PARAM_STR);
  $stmt21-&gt;execute();
  
  $thisuser = $stmt21-&gt;fetch(PDO::FETCH_ASSOC);
  $location = $thisuser['location'];
  
          echo'
          &lt;tr class="resultindex"&gt;
  
          &lt;td class="imgCol"&gt;&lt;a href="displayAuct.php?id='.$ID.'"&gt;&lt;img src="'.$img.'" alt="'.$name.'" /&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td class="infoCol"&gt;
  
              &lt;div class="nameDiv"&gt;
                  &lt;a class="nameLink" href="displayAuct.php?id='.$ID.'"&gt;'.$name.'&lt;/a&gt;&lt;br/&gt;
              &lt;/div&gt;
              &lt;div class="descDiv"&gt;
                  &lt;span class="priceLabel2"&gt;'.$desc.'&lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="userdiv"&gt;
                  &lt;span class="fromuser"&gt;Location: &lt;/span&gt;&lt;br/&gt;
                  &lt;span class="location"&gt;'.$location.'&lt;/span&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td style="width:1px; background-color:#330066;" &gt;&lt;/td&gt;
          &lt;td class="priceCol"&gt;
              &lt;div class="currentp"&gt;&lt;span class="priceLabel"&gt;Current Bid: &lt;/span&gt;&lt;br/&gt;&lt;span class="price1"&gt;$'.$cprice.'&lt;/span&gt;&lt;/div&gt;
              &lt;div class="instantp"&gt;&lt;span class="priceLabel2"&gt;Instant Sale: &lt;/span&gt;&lt;br/&gt;&lt;span class="price2"&gt;$'.$iprice.'&lt;/span&gt;&lt;/div&gt;
              &lt;div style="height:5px;"&gt;&lt;/div&gt;
              &lt;div class="incp"&gt;&lt;span class="priceLabel2"&gt;Next Bid:&lt;/span&gt;&lt;br/&gt;&lt;span class="price2"&gt;$'.$nextBid.'&lt;/span&gt;&lt;/div&gt;
          &lt;/td&gt;
          &lt;td style="width:1px; background-color:#330066;"&gt;&lt;/td&gt;
          &lt;td class="timerCol"&gt;
              &lt;div id="timeRow"&gt;
                  &lt;span class="timeleft"&gt;Time Left: &lt;/span&gt;
              &lt;/div&gt;
              &lt;div id="countdownRow"&gt;&lt;/div&gt;
  
              &lt;script type=text/javascript&gt;
              var timestamp = '. $etime * 1000 .';
              var endTime = new Date();
              endTime.setTime(timestamp);
  
  
  
              $("#countdownRow").countdown({until: endTime});
  
              &lt;/script&gt;
          &lt;/td&gt;
          &lt;/tr&gt;
          ';
      }
      if($numrows == 0){
  ?&gt;
          &lt;tr&gt;
          &lt;td colspan="6"&gt;&lt;span class="price1"&gt;Sorry your search returned no results&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
  &lt;?php
      }
      else{
  ?&gt;
          &lt;tr&gt;
          &lt;td colspan="6"&gt;&lt;span class="price1"&gt;Displaying &lt;?php echo $numrows; ?&gt; results&lt;/span&gt;&lt;/td&gt;
  
      &lt;/tr&gt;
  &lt;?php
      $pdo = null;
      }
      }catch(PDOException $e){
          echo $e-&gt;getMessage();
      }
  }
  ?&gt;
  
      &lt;/table&gt;
  
      &lt;/div&gt;
  &lt;?php
  }else{
  ?&gt;
      &lt;div id="searchresults"&gt;&lt;span style="font-style:italic; font-size: 14pt; font-family:Impact;"&gt;Hurry, these auctions dont have long left!:&lt;/span&gt;&lt;/div&gt;
      &lt;div id="content"&gt;
      &lt;table id="displaying" class="displayer"&gt;
  &lt;?php
  try{
      $time = time();
      $in15 = time() + 900;
      $stmt55 = $pdo-&gt;prepare('SELECT * FROM auction WHERE etime &lt; :etime AND etime &gt; :time ORDER BY etime');
      $stmt55-&gt;bindParam(':etime', $in15, PDO::PARAM_INT);
      $stmt55-&gt;bindParam(':time', $time, PDO::PARAM_INT);
  
      $stmt55-&gt;execute();
  
      while($row = $stmt55-&gt;fetch(PDO::FETCH_ASSOC)){
          $ID = $row['ID'];
          $img = $row['img'];
          $desc = $row['description'];
          $name = $row['name'];
          $owner = $row['owner'];
          $cprice = $row['sprice'];
          $iprice = $row['iprice'];
          $incprice = $row['incprice'];
          $etime = $row['etime'];
          $nextBid = $cprice + $incprice;
  
          $stmt23 = $pdo-&gt;prepare("SELECT * FROM user WHERE username = :username");
          $stmt23-&gt;bindParam(":username", $owner,PDO::PARAM_STR);
          $stmt23-&gt;execute();
  
          $thisuser = $stmt23-&gt;fetch(PDO::FETCH_ASSOC);
          $location = $thisuser['location'];
  
          echo'
          &lt;tr class="resultindex"&gt;
  
          &lt;td class="imgCol"&gt;&lt;a href="displayAuct.php?id='.$ID.'"&gt;&lt;img src="'.$img.'" alt="'.$name.'" /&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td class="infoCol"&gt;
  
              &lt;div class="nameDiv"&gt;
                  &lt;a class="nameLink" href="displayAuct.php?id='.$ID.'"&gt;'.$name.'&lt;/a&gt;&lt;br/&gt;
              &lt;/div&gt;
              &lt;div class="descDiv"&gt;
                  &lt;span class="priceLabel2"&gt;'.$desc.'&lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="userdiv"&gt;
                  &lt;span class="fromuser"&gt;Location: &lt;/span&gt;&lt;br/&gt;
                  &lt;span class="location"&gt;'.$location.'&lt;/span&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td style="width:1px; background-color:#330066;" &gt;&lt;/td&gt;
          &lt;td class="priceCol"&gt;
              &lt;div class="currentp"&gt;&lt;span class="priceLabel"&gt;Current Bid: &lt;/span&gt;&lt;br/&gt;&lt;span class="price1"&gt;$'.$cprice.'&lt;/span&gt;&lt;/div&gt;
              &lt;div class="instantp"&gt;&lt;span class="priceLabel2"&gt;Instant Sale: &lt;/span&gt;&lt;br/&gt;&lt;span class="price2"&gt;$'.$iprice.'&lt;/span&gt;&lt;/div&gt;
              &lt;div style="height:5px;"&gt;&lt;/div&gt;
              &lt;div class="incp"&gt;&lt;span class="priceLabel2"&gt;Next Bid:&lt;/span&gt;&lt;br/&gt;&lt;span class="price2"&gt;$'.$nextBid.'&lt;/span&gt;&lt;/div&gt;
          &lt;/td&gt;
          &lt;td style="width:1px; background-color:#330066;"&gt;&lt;/td&gt;
          &lt;td class="timerCol"&gt;
              &lt;div id="timeRow"&gt;
                  &lt;span class="timeleft"&gt;Time Left: &lt;/span&gt;
              &lt;/div&gt;
              &lt;div id="countdownRow"&gt;&lt;/div&gt;
  
              &lt;script type=text/javascript&gt;
              var timestamp = '. $etime * 1000 .';
              var endTime = new Date();
              endTime.setTime(timestamp);
  
  
  
              $("#countdownRow").countdown({until: endTime});
  
              &lt;/script&gt;
          &lt;/td&gt;
          &lt;/tr&gt;
          ';
  
      }
      $pdo = null;
      }catch(PDOException $e){
          echo $e-&gt;getMessage();
      }
  }
  ?&gt;
  
      &lt;/table&gt;
  
      &lt;/div&gt;
  
      &lt;div id="sitemap"&gt;
      &lt;/div&gt;
      &lt;/div&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>