Неустранимая ошибка: Uncaught PDOException: SQLSTATE [HY093]: недопустимый номер параметра: число связанных переменных не соответствует количеству токенов в - PullRequest
0 голосов
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
in C:\OSPanel\domains\Project1\models\Recipe.php:194
Stack trace:
#0 C:\OSPanel\domains\Project1\models\Recipe.php(194): PDOStatement->execute()
#1 C:\OSPanel\domains\Project1\controllers\AdminRecipeController.php(121): Recipe::updateRecipeById()
#2 C:\OSPanel\domains\Project1\components\Router.php(50): AdminRecipeController->actionUpdate()
#3 C:\OSPanel\domains\Project1\index.php(20): Router->run()
#4 {main} thrown in C:\OSPanel\domains\Project1\models\Recipe.php on line 194

Я не могу понять, в чем ошибка?

public static function updateRecipeById($id, $options)
{
    $db = Db::getConnection();

    $sql = "UPDATE `recipe`
        SET `cuisine_id` = :cuisine_id, 
            `Cooking_methodId` = :Cooking_methodId, 
            `name` = :name, 
            `category_id` = :category_id, 
            `ingredients` = :ingredients, 
            `short_content` = :short_content, 
            `cooking_method` = :cooking_method, 
            `Сaloric_content` = :Сaloric_content, 
            `relevance` = :relevance
        WHERE `id` = :id";

    $result = $db->prepare($sql);
    $result->bindValue(':id', $id, PDO::PARAM_INT);
    $result->bindValue(':cuisine_id', $options['cuisine_id'], PDO::PARAM_INT);
    $result->bindValue(':Cooking_methodId', $options['Cooking_methodId'], PDO::PARAM_INT);
    $result->bindValue(':name', $options['name'], PDO::PARAM_STR);
    $result->bindValue(':category_id', $options['category_id'], PDO::PARAM_INT);
    $result->bindValue(':ingredients', $options['ingredients'], PDO::PARAM_STR);
    $result->bindValue(':short_content', $options['short_content'], PDO::PARAM_STR);
    $result->bindValue(':cooking_method', $options['cooking_method'], PDO::PARAM_STR);
    $result->bindValue(':Сaloric_content', $options['Сaloric_content'], PDO::PARAM_STR);
    $result->bindValue(':relevance', $options['relevance'], PDO::PARAM_INT);
    return $result->execute(); // line 194

Я проверил все сто раз

public function actionUpdate($id)
{

    self::checkAdmin();

    $categoriesList = Category::getCategoriesListAdmin();

    $cuisineList = Category::getCuisineListAdmin();

    $cookingMethodList = Category::getCookingMethodListAdmin();


    $recipe = Recipe::getRecipeById($id);

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

        $options['cuisine_id'] = $_POST['cuisine_id'];
        $options['Cooking_methodId'] = $_POST['Cooking_methodId'];
        $options['name'] = $_POST['name'];
        $options['category_id'] = $_POST['category_id'];
        $options['ingredients'] = $_POST['ingredients'];
        $options['short_content'] = $_POST['short_content'];
        $options['cooking_method'] = $_POST['cooking_method'];
        $options['Сaloric_content'] = $_POST['Сaloric_content'];
        $options['relevance'] = $_POST['relevance'];

        if (Recipe::updateRecipeById($id, $options)) {

            if (is_uploaded_file($_FILES["image"]["tmp_name"])) {


               move_uploaded_file($_FILES["image"]["tmp_name"], $_SERVER['DOCUMENT_ROOT'] . "/upload/images/recipe/{$id}.jpg");
            }
        }

        header("Location: /admin/recipe");
    }

    require_once(ROOT . '/views/admin_recipe/update.php');
    return true;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...