插入值列表与列列表不匹配:1136列计数与值计数不匹配

时间:2016-03-31 07:48:44

标签: php mysql pdo

我有这个PHP-MySQL插入代码:

$sqlTeeth = "INSERT INTO teeth (id_logged, patient_id, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eightteen, nineteen, twenty, twone, twtwo, twthree, twfour, twfive, twsix, twseven, tweight, twnine, thirty, thone, thtwo, date_now) VALUES (:id_logged, :patient_id, :one, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten, :eleven, :twelve, :thirteen,
            :fourteen, :fifteen, :sixteen, :lone, :ltwo, :lthree, :lfour, :lfive, :lsix, :lseven, :leight, :lnine, :lten, :leleven, :ltwelve, :lthirteen,
            :lfourteen, :lfifteen, :lsixteen)";
        $sqlTeethStmt = $conn->prepare($sqlTeeth);
        $sqlTeethStmt->bindValue(":id_logged", $id_logged);
        $sqlTeethStmt->bindValue(":patient_id", $patient_id);
        $sqlTeethStmt->bindValue(":one", $one);
        $sqlTeethStmt->bindValue(":two", $two);
        $sqlTeethStmt->bindValue(":three", $three);
        $sqlTeethStmt->bindValue(":four", $four);
        $sqlTeethStmt->bindValue(":five", $five);
        $sqlTeethStmt->bindValue(":six", $six);
        $sqlTeethStmt->bindValue(":seven", $seven);
        $sqlTeethStmt->bindValue(":eight", $eight);
        $sqlTeethStmt->bindValue(":nine", $nine);
        $sqlTeethStmt->bindValue(":ten", $ten);
        $sqlTeethStmt->bindValue(":eleven", $eleven);
        $sqlTeethStmt->bindValue(":twelve", $twelve);
        $sqlTeethStmt->bindValue(":thirteen", $thirteen);
        $sqlTeethStmt->bindValue(":fourteen", $fourteen);
        $sqlTeethStmt->bindValue(":fifteen", $fifteen);
        $sqlTeethStmt->bindValue(":sixteen", $sixteen);

        $sqlTeethStmt->bindValue(":lone", $lone);
        $sqlTeethStmt->bindValue(":ltwo", $ltwo);
        $sqlTeethStmt->bindValue(":lthree", $lthree);
        $sqlTeethStmt->bindValue(":lfour", $lfour);
        $sqlTeethStmt->bindValue(":lfive", $lfive);
        $sqlTeethStmt->bindValue(":lsix", $lsix);
        $sqlTeethStmt->bindValue(":lseven", $lseven);
        $sqlTeethStmt->bindValue(":leight", $leight);
        $sqlTeethStmt->bindValue(":lnine", $lnine);
        $sqlTeethStmt->bindValue(":lten", $lten);
        $sqlTeethStmt->bindValue(":leleven", $leleven);
        $sqlTeethStmt->bindValue(":ltwelve", $ltwelve);
        $sqlTeethStmt->bindValue(":lthirteen", $lthirteen);
        $sqlTeethStmt->bindValue(":lfourteen", $lfourteen);
        $sqlTeethStmt->bindValue(":lfifteen", $lfifteen);
        $sqlTeethStmt->bindValue(":lsixteen", $lsixteen);

        $sqlTeethStmt->execute();

当我向数据库添加内容时,我收到了此错误:

  

SQLSTATE [21S01]:插入值列表与列表列表不匹配:1136   列数与第1行的值计数不匹配

感谢任何帮助。

2 个答案:

答案 0 :(得分:6)

您的数据库表有35列

@POST("users/new")
Call<User> createUser(@Body User newUser);

您传递的值为34列

id_logged, patient_id, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eightteen, nineteen, twenty, twone, twtwo, twthree, twfour, twfive, twsix, twseven, tweight, twnine, thirty, thone, thtwo, date_now

这些列不匹配会给您带来错误。

您忘记传递 date_now 列的值。一旦你通过它,错误将被解决

答案 1 :(得分:0)

SQLSTATE [21S01]:插入值列表与列列表不匹配:1136列计数与第1行的值计数不匹配

先前的回答绝对可以解释潜在的问题,但也可能有助于理解错误报告。它分为两个部分:

插入值列表不匹配列列表: SQL语句首先包含一个列列表,然后一个值列表,这两个不匹配。

1136列计数与第1行的值计数不匹配。问题是所列出的值的数量与所列出的列的数量不同。

SQL错误代码写得很简洁,看起来似乎很晦涩,但是一旦将它们分解,其含义通常非常简单。