Hi everybody,
I am Richard, and i am a biginner in the PHP MYSQL codification. I'm developping a online site, and i am facing to a blocking point, regarding the insertion of products onsite.
I have 2 tables:
- 1 for User Registration (containning the primary key: userID)
- 1 for Products registration (containning the foreign key: userID).
This is a part of my product insertion request: "INSERT INTO shopping.produits (userID, productID, product_picture, product_name, product_desc, product_price) VALUES ($dataID, NULL, $product_picture, $product_name, $product_desc, $product_price)"
If i replace variables ($product_picture, $product_name, $product_desc, $product_price) in VALUES attribut, by putting '', and execute the request, everything works well, but, when i put variables, and execute the request, this is the message i get:
" Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\04 - Shopping\PHP\addProduct.php:67 Stack trace: #0 C:\xampp\htdocs\04 - Shopping\PHP\addProduct.php(67): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\04 - Shopping\PHP\addProduct.php on line 67 "
Line 67 concerns the array.
Could you please help me?
Thant you in advance.
Regards,
Richard
What I have tried:
$req_insert_product = $bdd->prepare("SELECT *
FROM produits
INNER JOIN form1
ON produits.userID=form1.userID");
$req_insert_product->execute();
$all_datas = $req_insert_product->fetch();
$dataID = $all_datas['userID'];
$req_insert_products = $bdd->prepare("INSERT INTO shopping.produits (userID, productID, product_picture, product_name, product_desc, product_price) VALUES ($dataID, NULL, $product_picture, $product_name, $product_desc, $product_price)");
$req_insert_products->execute(array(
'userID' => $dataID,
'productID' => NULL,
'product_picture' => $product_picture,
'product_name' => $product_name,
'product_desc' => $product_desc,
'product_price' => $product_price
));