PHP-SQL: ошибка подсчета столбцов, но только не вставленное значение является первичным ключом

У меня есть таблица рецептов с 20 полями, и через форму я заполнил 19. Но получаю ошибку вставки — «Количество столбцов не соответствует значению в строке 1». Единственный столбец, который я не заполнил, — это значение первичного ключа с автоинкрементом (которое, я полагаю, должно само позаботиться о себе), поэтому я не уверен, почему происходит эта ошибка. Буду признателен за любую помощь.

Вот php:

<!DOCTYPE html>
<html>

<?php
require_once 'login_news.php';
include ('newscss.php');
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);if (isset($_POST['delete']) && isset($_POST['uniqno']))
{
$uniqno   = get_post($conn, 'uniqno');
$query  = "DELETE FROM recipes WHERE uniqno='$uniqno'";
$result = $conn->query($query);
if (!$result) echo "DELETE failed: $query<br>" .
$conn->error . "<br><br>";
}//var_dump($_FILES['imagine']);
if (isset($_POST['btn'])){
$recregion  = get_post($conn, 'recregion');
$recpostdate     = get_post($conn, 'recdate');
$recpostdate     = date('Y-m-d H:i:s', strtotime($recpostdate));
$rectitle   = get_post($conn, 'rectitle');
$recsummary   = get_post($conn, 'recsummary');
$reccontributor   = get_post($conn, 'reccontributor');
$ingredcontent     = get_post($conn, 'ingredcontent');
$prepsubhead1   = get_post($conn, 'prepsubhead1');
$prepcontent1 = get_post($conn, 'prepcontent1');
$prepsubhead2     = get_post($conn, 'prepsubhead2');
$prepcontent2   = get_post($conn, 'prepcontent2');
$prepsubhead3     = get_post($conn, 'prepsubhead3');
$prepcontent3   = get_post($conn, 'prepcontent3');
$prepsubhead4     = get_post($conn, 'prepsubhead4');
$prepcontent4   = get_post($conn, 'prepcontent4');
$prepsubhead5     = get_post($conn, 'prepsubhead5');
$prepcontent5   = get_post($conn, 'prepcontent5');

if($_FILES['imagine']['error'] != UPLOAD_ERR_NO_FILE){
$filetmp = $_FILES["imagine"]["tmp_name"];
$recpicname = $_FILES["imagine"]["name"];
$recpictype = $_FILES["imagine"]["type"];
$recpicpath = "images/".$recpicname;

move_uploaded_file($filetmp, $recpicpath);

$query    = "INSERT INTO recipes VALUES" .
"('$recregion', '$recpostdate', '$rectitle', '$recsummary', '$reccontributor', '$recpicname', '$recpicpath', '$recpictype',
'$ingredcontent', '$prepsubhead1', '$prepcontent1', '$prepsubhead2', '$prepcontent2', '$prepsubhead3',
'$prepcontent3', '$prepsubhead4', '$prepcontent4', '$prepsubhead5', '$prepcontent5')";
$result   = $conn->query($query);

if (!$result) echo "INSERT failed: $query<br>" .
$conn->error . "<br><br>";
}
else{

$query    = "INSERT INTO recipes VALUES" .
"('$recregion', '$recpostdate', '$rectitle', '$recsummary', '$reccontributor', '$ingredcontent',
'$prepsubhead1', '$prepcontent1', '$prepsubhead2', '$prepcontent2', '$prepsubhead3',
'$prepcontent3', '$prepsubhead4', '$prepcontent4', '$prepsubhead5', '$prepcontent5')";
$result   = $conn->query($query);

if (!$result) echo "INSERT failed: $query<br>" .
$conn->error . "<br><br>";

}
}

?>
<form action="recipes.php" method="post" enctype="multipart/form-data"><pre>
Recipe's Region <input type="text" name="recregion">
Date of Posting <input type="text" name="recdate">
RecipeTitle <input type="text" name="rectitle">
Summary <textarea rows="5" cols="60" name="recsummary"></textarea>
Contributor <input type="text" name="reccontributor">
Ingredient Content <textarea rows="15" cols="60" name="ingredcontent"></textarea>
Preparation Subhead1 <input type="text" name="prepsubhead1">
Preparation Content1 <textarea rows="15" cols="60" name="prepcontent1"></textarea>
Preparation Subhead2 <input type="text" name="prepsubhead2">
Preparation Content2 <textarea rows="15" cols="60" name="prepcontent2"></textarea>
Preparation Subhead3 <input type="text" name="prepsubhead3">
Preparation Content3 <textarea rows="15" cols="60" name="prepcontent3"></textarea>
Preparation Subhead4 <input type="text" name="prepsubhead4">
Preparation Content4 <textarea rows="15" cols="60" name="prepcontent4"></textarea>
Preparation Subhead5 <input type="text" name="prepsubhead5">
Preparation Content5 <textarea rows="15" cols="60" name="prepcontent5"></textarea>

<input type="file" name="imagine">
<input type="submit" name="btn" value="Upload Image & ADD RECIPE RECORD">
</pre></form><?phpfunction get_post($conn, $var)
{
return $conn->real_escape_string($_POST[$var]);
}

?>
</html>

Вот полное сообщение об ошибке:

INSERT не удалось: INSERT INTO рецепты ЦЕННОСТИ (‘Ассам’, ‘2000-12-12
00:00:00 »,« Крылышки »,« Лучший способ съесть свое сердце »,« Валия »,
‘firstfood.jpg’, ‘images / firstfood.jpg’, ‘image / jpeg’,
‘Вода \ r \ npaper \ r \ nnuts \ r \ nbarberries \ r \ nбамбуковые побеги’, ‘Wash’, ‘Wash
тщательно высушить, высушить, пожарить на сковороде, добавить
специи, дайте остыть, добавьте воды, положите в дождевую воду, перемешайте,
«Соль», «Добавьте гималайскую морскую соль», «Пойте», «Поднесите блюдо»
хорошо ‘) Количество столбцов не соответствует количеству значений в строке 1

А вот структура таблицы:
введите описание изображения здесь

0

Решение

Ваша таблица имеет 20 столбцов, но вы добавляете только 18 значений в запрос вставки.
Вы должны добавить имена столбцов или нулевые значения в столбец, который вы не будете заполнять значениями.

insert into recipes (<column names>) values(<values>)

Более подробную информацию о вставке в синтаксис смотрите на официальном документация

0

Другие решения

В вашем запросе отсутствует столбец uniqno, поэтому он выдает ошибку. Число столбцов не совпадает.
замещать

 $query    = "INSERT INTO recipes VALUES" .
"('$recregion', '$recpostdate', '$rectitle', '$recsummary', '$reccontributor', '$ingredcontent',
'$prepsubhead1', '$prepcontent1', '$prepsubhead2', '$prepcontent2', '$prepsubhead3',
'$prepcontent3', '$prepsubhead4', '$prepcontent4', '$prepsubhead5', '$prepcontent5')";

с

 $query    = "INSERT INTO recipes VALUES" .
"('','$recregion', '$recpostdate', '$rectitle', '$recsummary', '$reccontributor', '$ingredcontent',
'$prepsubhead1', '$prepcontent1', '$prepsubhead2', '$prepcontent2', '$prepsubhead3',
'$prepcontent3', '$prepsubhead4', '$prepcontent4', '$prepsubhead5', '$prepcontent5')";
0

Да — это было решено с помощью комментария к вопросу @Sougata — однако не может пометить его как ответ, как в комментарии. Как многие уже указывали, проблема заключалась в том, что я не указал, к каким столбцам применяются значения, в запросе INSERT. В конце концов использовал это:

$query    = "INSERT INTO recipes (recregion, recpostdate, rectitle, recsummary, reccontributor, recpicname, recpicpath, recpictype,
ingredcontent, prepsubhead1, prepcontent1, prepsubhead2, prepcontent2, prepsubhead3,
prepcontent3, prepsubhead4, prepcontent4, prepsubhead5, prepcontent5) VALUES" .
"('$recregion', '$recpostdate', '$rectitle', '$recsummary', '$reccontributor', '$recpicname', '$recpicpath', '$recpictype',
'$ingredcontent', '$prepsubhead1', '$prepcontent1', '$prepsubhead2', '$prepcontent2', '$prepsubhead3',
'$prepcontent3', '$prepsubhead4', '$prepcontent4', '$prepsubhead5', '$prepcontent5')";
$result   = $conn->query($query);
0