Need help with Database create function

I am trying to add a create function to a school project someone in my group made a function for creating and I am trying to use it but it just doesn’t insert into the database this is what he has

 //insert functions
    //...
    //function for products
    public function insertRecordToProducts ($product_type, $name, $Description, $img_url, $price) {
        $qeury = "INSERT INTO products (product_type, name, Description, img_url, price)
                  VALUES ('$product_type', '$name', '$Description', '$img_url', '$price')";

        $this->dbh()->query($qeury);
    }

and this is what I have

 if (isset($_POST['create']))
        {
            $p_id = $_POST['product_id'];
            $db->insertRecordToProducts('product_type','name','Description','img_url','url');
        }

if anyone could tell me what I did wrong that would be amazing tysm! Just need to call his function :smiley:

 /* Should use prepared statememts and this is using PDO */       
/* Name conventioning should be all lowercase for arguments/Variables */
$sql = “INSERT INTO products (product_type, name, Description, img_url, price) 
            VALUES 
           ( product_type=:product_type, 
             name=:name, 
             Description=:Description, 
             img_url=:img_url, 
             price=:price )”;
       $stmt = $this->dbh()->prepare($sql);
       return $stmt->execute([
            'product_type' => $product_type, 
            'name' => $name, 
            'Description' => $Description, 
            'img_url' => $img_url, 'price' => price
       ]);

One good source to learn PDO is https://phpdelusions.net/pdo and you should have error reporting turned on.

Sponsor our Newsletter | Privacy Policy | Terms of Service