Fatal error: Uncaught Error: Call to a member function prepare() on null in D:\p\htdocs\shop\produktnew.php:31 Stack trace: #0 D:\p\htdocs\shop\produktnew.php?
Fatal error: Uncaught Error: Call to a member function prepare() on null in D:\p\htdocs\shop\produktnew.php:31 Stack trace: #0 D:\p\htdocs\shop\produktnew.php(92): createProduct('yxy', 'e', 'yasdd ', 0) #1 {main} thrown in D:\p\htdocs\shop\produktnew.php on line 31
function createProduct(string $productName, string $slug, string $description, int $price): bool
{
$sql = "INSERT INTO products SET
title = :productName,
slug = :slug,
description = :description,
price = :price
";
was mache ich falsch
2 Antworten
![](https://images.gutefrage.net/media/default/user/7_nmmslarge.png?v=1438863662000)
Nutzer, der sehr aktiv auf gutefrage ist
Sieht für mich so aus, als wüden die Übergabeparameter der Funktion nie an die Variablen im sql-String gebunden.
Ist aber schwierig zu sagen, da du ja viele Informationen vorenhältst.
Woher ich das weiß:eigene Erfahrung – Ich habe selber lange im PC gearbeitet
![](https://images.gutefrage.net/media/user/RakonDark/1552185525294_nmmslarge__0_0_160_160_7f828fad18ee7edb96b8daceedaeeadb.png?v=1552185525000)
Nutzer, der sehr aktiv auf gutefrage ist
das problem tritt erst später auf beim prepare .
![](https://images.gutefrage.net/media/user/Schachpapa/1456653634658_nmmslarge__116_32_432_432_d36a6a6d62721271685e85017f4dbcb0.jpg?v=1456653637000)
Schachpapa
04.03.2022, 15:29
@tobi3443549thz
Steht doch in der Fehlermeldung:
Call to a member function prepare() on null
Offenbar liefert getDB() einen Null-Wert
wo ist da das problem