简体   繁体   中英

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? 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. 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?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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