И так я делаю простенький сайт и дошла очередь до админпанели. И почему то у меня не работает редактирование(UPDATE).. Программирую в стиле ооп..
Вот код контроллера:
public function actionUpdate($id){
self::checkAdmin();
$categoriesList = Category::getCategoryListAdmin();
$recipe = Recipes::getRecipesById($id);
if(isset($_POST['submit'])){
$options['name'] = $_POST['name'];
$options['category_id'] = $_POST['category_id'];
$options['short_content'] = $_POST['short_content'];
$options['content'] = $_POST['content'];
$options['author'] = $_POST['author'];
$options['is_popul'] = $_POST['is_popul'];
$options['status'] = $_POST['status'];
if(Recipes::updateRecipesById($id, $options)){
// Проверка загрузилось ли через форму изображение
if(is_uploaded_file($_FILES["image"]["tmp_name"])){
// Если загрузилось, переместим его в нужную папку, дадим новое имя
move_uploaded_file($_FILES["image"]["tmp_name"], $_SERVER['DOCUMENT_ROOT'] . "/upload/images/recipes/{$id}.jpg");
}
}
header("Location: /admin/product");
echo mysql_error();
}
require_once(ROOT . '/views/admin_recipes/update.php');
return true;
}
Вот код модели:
public static function updateRecipesById($id, $options){
$db = Db::getConnection();
$sql = "UPDATE recipes
SET
name = :name,
category_id = :category_id,
short_content = :short_content,
content = :content,
author = :author,
is_popul = :is_popul,
status = :status
WHERE id = :id ";
$result = $db->prepare($sql);
$result->bindParam(':id', $id, PDO::PARAM_INT);
$result->bindParam(':name', $options['name'], PDO::PARAM_STR);
$result->bindParam(':short_content', $options['short_content'], PDO::PARAM_STR);
$result->bindParam(':content', $options['content'], PDO::PARAM_STR);
$result->bindParam(':author', $options['author'], PDO::PARAM_STR);
$result->bindParam(':is_popul', $options['is_popul'], PDO::PARAM_INT);
$result->bindParam(':status', $options['status'], PDO::PARAM_INT);
return $result->execute();
}
Выдает такую ошибку:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\wamp\www\models\Recipes.php on line 137
На 137 линии такой код: return $result->execute();
Помогите знатаки, а то я уже не могу пару дней страдаю и не могу ничего сделать..
|