简体   繁体   English

我收到此错误,有人可以帮忙吗? 列数与第1行的值数不匹配

[英]I get this error, can someone help? Column count doesn't match value count at row 1

Column count doesn't match value count at row 1 Can someone help me pls? 列数与第1行的值数不匹配有人可以帮我吗? I can't figure it out ... 我不知道...

if (isset($_POST['prodotto_cat'])) {

$product_cat = mysqli_real_escape_string($conn,$_POST['prodotto_cat']);
$category_cat = mysqli_real_escape_string($conn,     $_POST['categoria_cat']);
$details_cat = mysqli_real_escape_string($conn,     $_POST['dettagli_cat']);

$sql = mysqli_query($conn, "SELECT id FROM prodotti_cat WHERE     product_cat='$product_cat' LIMIT 1");
$productMatch_cat = mysqli_num_rows($sql); // count the output amount
if ($productMatch_cat > 0) {
    echo 'Mi dispiace, hai inserito un duplicato "Nome prodotto" nel     sistema, <a href="admin.php">&nbsp; &nbsp; &nbsp; RITORNA</a>';
    exit();
}

$sql = mysqli_query($conn, "INSERT INTO prodotti_cat (product_cat,     details_cat,  category_cat)
  VALUES('$product_cat','$details_cat','$category_cat',now())") or die     (mysqli_error($conn));
  $pid_cat = mysqli_insert_id($conn);

You are trying to insert 4 values into 3 columns. 您试图将4个值插入3列。 Observe: 观察:

INSERT INTO prodotti_cat (product_cat,    details_cat,    category_cat)
                  VALUES ('$product_cat', '$details_cat', '$category_cat', now())

What column should hold that now() value? 哪一列应该包含now()值?

Either add the fourth column to the column list, or remove the 4th value from the value list. 将第四列添加到列列表,或从值列表中删除第四个值。


While you're at it, you should also start looking into what SQL Injection is, because currently your code is potentially open to it. 在使用它的同时,您还应该开始研究什么是SQL注入,因为当前您的代码可能对它开放。 This is a good place to start, as is this . 是一个良好的开端,因为是这样 While you are trying to prevent the problem by sanitizing input, that alone is not enough. 当您尝试通过清除输入来解决问题时,仅此还不够。 Instead of trying to prevent users from inputting malicious code, simply don't execute user input as code in the first place. 与其试图阻止用户输入恶意代码,不如首先不要将用户输入作为代码来执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM