0

I'm making a form where you can enter your own product and add it to the store (it's a project) but whenever I press on "Add" I keep getting this error message:

Fatal error: Call to a member function execute() on boolean in

$query = "INSERT INTO tbl_product (id, name, image, price, lager, age) VALUES (NULL, :name, :image, :price, :lager, :age)";
$stmt = $mysqli -> prepare($query);

$stmt -> execute(array(
  ":name" => $name,
  ":image" => $image,
  ":price" => $price,
  ":lager" => $lager,
  ":age" => $age));

I've checked and all the variables exist and they work, I've tried with echo and so on to check. Any help is greatly appreciated!

chris85
  • 23,846
  • 7
  • 34
  • 51
Momo
  • 11
  • Check for errors after you prepare your query. – aynber Oct 28 '16 at 13:08
  • 5
    `mysqli` doesn't support named parameters. The `execute` syntax also is `PDO`. See http://php.net/manual/en/mysqli.quickstart.prepared-statements.php. – chris85 Oct 28 '16 at 13:09
  • @chris85 exactly. – u_mulder Oct 28 '16 at 13:09
  • `$mysqli->prepare` must have failed, if you do a `var_dump($stmt);`, it should echo `bool(false)` – roberto06 Oct 28 '16 at 13:10
  • Something like `$stmt->bind_param("ssssi", $name, $image, $price, $lager, $age); $stmt->execute();` should work. After altering the query to use unnamed placeholders (and remove `id` because it is not needed if auto-incrementing) – chris85 Oct 28 '16 at 13:15
  • I see the word `mysqli` and `:` (PDO) placeholders.. *Hmmm....*, smells like mixing APIs here. – Funk Forty Niner Oct 28 '16 at 13:19

0 Answers0