0

抱歉,对 PHP 和 mySQL 很陌生。

这是错误所指的代码。

$query = 'INSERT INTO movies
            (title, year, actor, notes, category)
          VALUES
            (:code, :name, :price, :notes, :category_id)';
$statement = $db->prepare($query);
$statement->bindValue(':title', $code);
$statement->bindValue(':year', $name);
$statement->bindValue(':actor', $price);
$statement->bindValue(':notes', $notes);
$statement->bindValue(':category', $category_id);
$statement->execute();
$statement->closeCursor();

错误是指execute(); 声明任何帮助都会很棒。

4

1 回答 1

0

我认为它应该是这样的,带有适当的变量绑定,在做的时候使用了错误的名字。我们开始做吧-

$query = 'INSERT INTO
            movies(title, year, actor, notes, category)
          VALUES 
            (:code, :name, :price, :notes, :category_id)';

$statement = $db->prepare($query);
$statement->bindValue(':code', $code); // see the changes here 
$statement->bindValue(':name', $name); // see the changes here 
$statement->bindValue(':price', $price); // see the changes here 
$statement->bindValue(':notes', $notes);// see the changes here  
$statement->bindValue(':category_id', $category_id); // see the changes here 
$statement->execute();
$statement->closeCursor();

PDOStatement::bindValue — 将值绑定到参数。

范围

参数标识符。对于使用命名占位符的准备好的语句,这将是一个形式为 :name 的参数名称。对于使用问号占位符的预处理语句,这将是参数的 1 索引位置。

价值

要绑定到参数的值。

但是在您的情况下,您在使用bindValue(). 查看更多http://php.net/manual/en/pdostatement.bindvalue.php

于 2018-10-17T01:42:01.617 回答