W
W
wolverine7772021-02-20 20:09:40
PHP
wolverine777, 2021-02-20 20:09:40

How to insert data from parameter using "prepare" SQL request?

Hello, I've just started learning MVC, so don't scold me too much for the title of the question. I'll try to explain what the problem is.

In the class "product" (produit) I'm trying to create a function that will add a name, price and picture to the database. The problem is that the image on localhost is located in the Images. If I use a regular ( не-prepare) request - no problem, everything works.

As soon as I try to do it prepare, I get errors:

( ! ) Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Images' in 'field list' in X:\WAMP\www\BonbonMVC2021\modeles\Produit.class.php on line 62


( ! ) PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Images' in 'field list' in X:\WAMP\www\BonbonMVC2021\modeles\Produit.class.php on line 62


public static function create($name, $price, $pic ) {
        $req = MonPdo::getInstance()->prepare("            
                                        INSERT INTO produit (nom, prix, photo) 
                                        VALUES (:name,:price,Images/:pic)
                                        "); // object creation of data from BD
        $req->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,'produit');                 
        $req->execute(array("name"=>$name,"price"=>$price,"pic"=>$pic));
        $leResultat=$req->fetchAll();
        return $leResultat;
    }


How can this be fixed or maybe it's not about that at all?

Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question