为什么我的插入表单不起作用?
public function safeCar() {
$asd = "INSERT INTO
'Car'(mark,
model,
year,
state_num,
mileage,
colour,
consumption,
cost_less_30_inc,
cost_more_31)
VALUES('$this->mark',
'$this->model',
$this->year,
$this->state_num,
$this->mileage,
'$this->colour',
$this->consumption,
$this->cost_less_30,
$this->cost_more_31)";
echo($asd);
$this->db->prepare($asd)->execute();
我正在通过POST发送表单并尝试将数据添加到数据库中。但PHP发给我一个错误
致命错误:未捕获错误:在...中的字符串上调用成员函数prepare()
..
但是我的字符串看起来很棒
INSERT INTO'Car'(标记,型号,年份,state_num,里程,颜色,消耗,cost_less_30_inc,cost_more_31)VALUES('Fiat','Punto',2003,345,32929,'black',7,10 ,7)
它适用于phpMyAdmin
我犯了错误?
var - db其PDO对象
答案 0 :(得分:0)
$prepare = $this->db->prepare("INSERT INTO Car (mark, model, year,state_num,mileage,colour, consumption, cost_less_30_inc, cost_more_31)
VALUES (:mark, :model, :year, :state_num,:mileage,:colour,:consumption,:cost_less_30_inc,:cost_more_31)");
$prepare->execute(array(
'mark' => 'Honda',
'year' => 2016,
...
...
);