PHP MySQL INSERT查询未插入到表中


PHP MySQL INSERT query not inserting to table

我不明白INSERT查询失败的原因。我在phpMyAdmin中仔细检查了查询,它运行良好,但当它被放入PHP时,它会失败。

PHP:

if (isset($_POST['create'])){
    //Insert booking to the database
    $InsertQuery = DB::getInstance()->query("INSERT INTO booking (`StartDate`, `EndDate`, `UserId`, `ItemId`) VALUES (
        '{$_POST['startdate']}', '{$_POST['enddate']}', {$_POST[currentuser]}, {$_POST[itemid]}");
    print_r($InsertQuery);
}

HTML:

<form action="MakeABooking1.php" method="post">
                    <tr>
                    <td><input type="text" name="itemid" value=" <?php echo $ItemId ?> "> </td>
                    <td><input type="text" name="currentuser" value=" <?php echo $currentUser ?> "> </td>
                    <td><input type="text" name="startdate" value=" <?php echo $bookFrom ?> "> </td>
                    <td><input type="text" name="enddate" value=" <?php echo $bookTo ?> "> </td>
                    <td><input type="submit" name="create" value="Book"></td>
                    </tr>
                    </form>

执行print_r($InsertQuery);显示以下内容:

DB对象([_pdo:DB:private]=>pdo对象()[_query:DB:private]=>PDOStatement Object([queryString]=>INSERT INTO booking(StartDateEndDateUserIdItemId)VALUES('2015-03-26','2015-03-31',48,8)[_error:DB:private]=>1[_results:DB:private]=>数组()[_count:DB:private]=>0)

当从print_r复制查询时,它是有效的,并创建预订。我哪里错了?

好吧,原来我的SQL查询中有一个错误,在我的VALUES列表之后缺少a)。不要撒谎,感觉很笨!谢谢你的所有建议。