PDO例外42000

时间:2015-07-19 20:26:54

标签: sql pdo

我试图将数据插入到我的数据库中,但我一直收到这个我无法弄清楚的错误。遍布论坛,无法找到答案,所以我想我会发帖。

完整错误以供参考。

error

代码:

    <?php
    $Records = $connect->query('SELECT COUNT(ID) as counted FROM listings;');
    $fetchdata = $Records->fetch();
    $i = $fetchdata['counted'];
    $i++;
    $name = 'hold';
    $OS = 0;

    if(isset($_POST['name'])){
     $name = $_POST['name'];
     $type = $_POST['type'];
     $loc = $_POST['loc'];
     $desc = $_POST['desc'];
     $prem = $_POST['premium'];

     }

    if($name != 'hold'){
     $sql = "INSERT INTO listings (name,premium,location,type,desc,onsite,ID,paymentid) VALUES (:Name,:Prem,:Loc,:Type,:Desc,:Onsite,:ID,:Paymentid);";
     $Appquery = $connect->prepare($sql);
     $Appquery->bindParam(':Name', $name, \PDO::PARAM_STR);
     $Appquery->bindParam(':Prem', $prem, \PDO::PARAM_INT);
     $Appquery->bindParam(':Loc', $loc, \PDO::PARAM_STR);
     $Appquery->bindParam(':Type', $type, \PDO::PARAM_STR);
     $Appquery->bindParam(':Desc', $desc, \PDO::PARAM_STR);
     $Appquery->bindParam(':Onsite', $OS, \PDO::PARAM_INT);
     $Appquery->bindParam(':ID', $i, \PDO::PARAM_INT);
     $Appquery->bindParam(':Paymentid', $i, \PDO::PARAM_INT);

     $Appquery->execute();
     header("Location: index.php"); 
     }
    ?>

1 个答案:

答案 0 :(得分:0)

desctype are reserved MySQL keywords。只需引用它们:

$sql = "INSERT INTO listings (name,premium,location,`type`,`desc`,onsite,ID,paymentid) VALUES (:Name,:Prem,:Loc,:Type,:Desc,:Onsite,:ID,:Paymentid);";
//                                                  ^    ^ ^    ^