0

Why my insert-form isn't works?

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();

I'm sending form via POST and trying to add data into DB. But php sent me a error

Fatal error: Uncaught Error: Call to a member function prepare() on string in ...

..

But my string looks so good

INSERT INTO 'Car'(mark, model, year, state_num, mileage, colour, consumption, cost_less_30_inc, cost_more_31) VALUES('Fiat', 'Punto', 2003, 345, 32929, 'black', 7, 10, 7)

it works in phpMyAdmin

Where I made a mistake?

var - db its PDO object

1 Answers1

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,
     ...
     ...
);
Mert Simsek
  • 1,550
  • 9
  • 19