php - PDO query: SQLSTATE[42000] -


when trying insert data mysql table using pdo following error.

fatal error: uncaught exception 'pdoexception' message 'sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 1' in /home/gaz492/public_html/dayz/user/pages/admin/vip.php:26 stack trace: #0 /home/gaz492/public_html/dayz/user/pages/admin/vip.php(26): pdo->query('insert `cu...') #1 /home/gaz492/public_html/dayz/user/index.php(89): include_once('/home/gaz492/pu...') #2 {main} thrown in /home/gaz492/public_html/dayz/user/pages/admin/vip.php on line 26

here code on page.

if able mean lot have been searching everywhere fix, cannot find works. ask if need more information , happy provide information need.

<?php /**  * created jetbrains phpstorm.  * user: gareth  * date: 14/07/13  * time: 19:01  * change template use file | settings | file templates.  */ ini_set('display_errors', 'on'); error_reporting(e_all); $news = "";  if ($loggedin === false) { echo "please log in access admin panel."; include_once("login.php"); } else {      $uid = $_session['adminid'];      if(isset($_request['addpackagebtn'])) {         $packagename = $_post['inputname'];         $packageinventory = $_post['inputinventory'];         $packagebackpack = $_post['inputbackpack'];         $packageskin = $_post['inputskin'];          $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception);         //$dbh->query("insert `cust_loadout`(`inventory`, `backpack`, `model`, `description`) values ('". $packageinventory ."','". $packagebackpack ."','". $packageskin ."','". $packagename . "'");         $dbh->query("insert `cust_loadout` (`inventory`, `backpack`, `model`, `description`) values ([],[],[],[]");     }      ?>     <h1>manage vip's</h1>      <table class="table table-striped table-bordered span8">         <thead>         <tr>             <th>delete</th>             <th>unique id</th>             <th>package</th>         </tr>         </thead>         <tbody>         <?php         foreach ($dbh->query("select * cust_loadout_profile") $vip) {          echo "<tr>";         echo "<td>delete</td>";         echo "<td>".$vip["unique_id"]."</td>";         echo "<td>".$vip["cust_loadout_id"]."</td>";         echo "</tr>";           }     ?>         </tbody>     </table>      <table class="table table-striped table-bordered span3">         <thead>         <tr>             <th>manage vip's</th>         </tr>         </thead>         <tbody>         <tr>             <td>                 <a href="#addvip" role="button" data-toggle="modal" class="btn btn-primary"><i class="icon-white icon-plus-sign"></i> add vip</a>             </td>         </tr>         <tr>             <td>                 <a href="#addpackage" role="button" data-toggle="modal" class="btn btn-primary"><i class="icon-white icon-plus-sign"></i> add vip package</a>             </td>         </tr>         </tbody>     </table>      <table class="table table-striped table-bordered span8">         <thead>         <tr>             <th>delete</th>             <th>name</th>             <th>inventory</th>             <th>backpack</th>             <th>skin</th>         </tr>         </thead>         <tbody>         <?php         foreach ($dbh->query("select * cust_loadout") $vip) {              echo "<tr>";             echo "<td>delete</td>";             echo "<td>".$vip["description"]."</td>";             echo "<td>".$vip["inventory"]."</td>";             echo "<td>".$vip["backpack"]."</td>";             echo "<td>".$vip["model"]."</td>";             echo "</tr>";           }         ?>         </tbody>     </table>      <!-- add vip modal -->     <div id="addvip" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addviplabel" aria-hidden="true">         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>             <h3 id="addviplabel">add vip</h3>         </div>         <div class="modal-body">             <form class="form-horizontal">                 <div class="control-group">                     <label class="control-label" for="inputuniqueid">unique id</label>                     <div class="controls">                         <input type="text" id="inputuniqueid" placeholder="unique id">                     </div>                 </div>                 <div class="control-group">                     <label class="control-label" for="inputpackage">package</label>                     <div class="controls">                         <input type="text" id="inputpackage" placeholder="package">                     </div>                 </div>                 <div class="control-group">                     <div class="controls">                     </div>                 </div>          </div>         <div class="modal-footer">             <button class="btn" data-dismiss="modal" aria-hidden="true">close</button>             <button type="submit" class="btn btn-primary">save changes</button>             </form>         </div>     </div>      <!-- add vip package modal -->     <div id="addpackage" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addpackageplabel" aria-hidden="true">         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>             <h3 id="addpackagelabel">add vip package</h3>         </div>         <div class="modal-body">             <form class="form-horizontal" acion="./?p=admin/vip" method="post">                 <div class="control-group">                     <label class="control-label" for="inputname">name</label>                     <div class="controls">                         <input type="text" id="inputname" name="inputname" placeholder="name">                     </div>                 </div>                 <div class="control-group">                     <label class="control-label" for="inputinventory">inventory</label>                     <div class="controls">                         <input type="text" id="inputinventory" name="inputinventory"  placeholder="inventory">                     </div>                 </div>                 <div class="control-group">                     <label class="control-label" for="inputbackpack">backpack</label>                     <div class="controls">                         <input type="text" id="inputbackpack" name="inputbackpack" placeholder="backpack">                     </div>                 </div>                 <div class="control-group">                     <label class="control-label" for="inputskin">skin</label>                     <div class="controls">                         <input type="text" id="inputskin" name="inputskin" placeholder="skin">                     </div>                 </div>                 <p>click <a href="./pages/loadouts/loadout.php" onclick="window.open(this.href, 'mywin', 'left=20,top=20,width=726px,height=481,toolbar=1,resizable=0'); return false;" >here</a> generate inventory string</p>          </div>         <div class="modal-footer">             <button class="btn" data-dismiss="modal" aria-hidden="true">close</button>             <button type="submit" name="addpackagebtn" class="btn btn-primary">save changes</button>             </form>         </div>     </div> <?php }  ?> 

change

    //$dbh->query("insert `cust_loadout`(`inventory`, `backpack`, `model`, `description`) values ('". $packageinventory ."','". $packagebackpack ."','". $packageskin ."','". $packagename . "'");     $dbh->query("insert `cust_loadout` (`inventory`, `backpack`, `model`, `description`) values ([],[],[],[]"); } 

to

    $stm = $dbh->prepare("insert `cust_loadout`(`inventory`, `backpack`, `model`, `description`) values (?, ?, ?, ?)");     $stm->execute( array($packageinventory, $packagebackpack, $packageskin, $packagename) ) } 

Comments