function add_product( $product_name, $product_brand, $product_type,
$product_description,$product_price, $number,
$reservefee, $status,$image,$supplier_id )
{
global $data,$sth;
$con = new mysqli("localhost","root","","eeee");
$sth = $con->prepare( "INSERT INTO products
(product_name,product_brand,product_type,
product_description,product_price,number,reservefee,
status,image,supplier_id)
VALUES(0,?,?,?,?,?,?,?,?,?,?)" );
$sth->bind_param('ssssiiisbi', $product_name, $product_brand, $product_type,$product_description,$product_price, $number, $reservefee, $status,$image,$supplier_id);
$sth->execute();
$data []= array(
'product_name' => $product_name,
'product_brand' => $product_brand,
'product_type' => $product_type,
'product_description' => $product_description,
'product_price' => $product_price,
'number' => $number,
'reservefee' => $reservefee,
'status' => $status,
'image' => $image,
'supplier_id' => $supplier_id
);
}
Asked
Active
Viewed 224 times
-1

RiggsFolly
- 93,638
- 21
- 103
- 149

Murithi H
- 11
- 1
-
It seems there is an error in your query... – Adam Forbis Sep 23 '16 at 14:01
-
And line 13 **is which line??** – RiggsFolly Sep 23 '16 at 14:01
-
@RiggsFolly should be the one with bind_param on it. – Adam Forbis Sep 23 '16 at 14:02
-
The prepare failed probably an issue in the query. You cont bother to check for an error so the code tries to use `$stmt` which is now `= false` and is not an object. Therefore you get the error when you try and use it in the `bind_value` – RiggsFolly Sep 23 '16 at 14:02
-
@AdamForbis Yea I know, but it is useful to remind the questioner of the sort of information they shoudl provide when asking for help. NOTE: There is no ` – RiggsFolly Sep 23 '16 at 14:04
-
1Your INSERT statement specifies 10 fields yet you offer 11 values... – fvu Sep 23 '16 at 14:04
-
1See http://stackoverflow.com/questions/2552545/mysqli-prepared-statements-error-reporting to learn more about prepared statements error handling – fvu Sep 23 '16 at 14:06
-
What is the 0 value? and you should use single quotes **'** , somwhere in the string you have **number** and seems the PHP interprets it. – M. I. Sep 23 '16 at 14:06
-
line 13 $sth->bind_param('ssssiiisb', $product_name, $product_brand, $product_type, $product_description,$product_price, $number, $reservefee, $status,$image); – Murithi H Sep 23 '16 at 14:19
1 Answers
2
You have an error in $con->prepare
, so it has returned false
therfore the bind_param
has failed as it is not working on a mysqli_statement
object.
Try deleting one of ?
from your VALUES clause in the prepare, because you are telling mysql to insert 11 parameters into 10 column names.

RiggsFolly
- 93,638
- 21
- 103
- 149

Samuel Loog
- 272
- 1
- 2
- 18
-
i have removed some fields but it is not working. $con = new mysqli("localhost","root","","electronicsshop"); $sth = $con->prepare( "INSERT INTO products('product_name','product_brand','product_type','product_description',product_price,number,reservefee,'status','image') VALUES(?,?,?,?,?,?,?,?,?)" ); $sth->bind_param('ssssiiisb', $product_name, $product_brand, $product_type, $product_description,$product_price, $number, $reservefee, $status,$image); $sth->execute(); – Murithi H Sep 23 '16 at 14:15
-
1@MurithiH Randomly changing things is not the solution. Apply a little logic to what you are doing – RiggsFolly Sep 23 '16 at 14:17
-
1Now you have 10 columns names and 9 `?` parameters **Its simple mathematics!** – RiggsFolly Sep 23 '16 at 14:20
-
When you get that right, remember you have to then provide the same (correct) number of values in the `bind_param()` statement as well to match the number of `?` in the VALUE clause – RiggsFolly Sep 23 '16 at 14:22
-
@MurithiH PS: nobody can read code in a comment. If you want to add additional information then EDIT you question. Add more info at the bottom and label its as "Additional Info" or something – RiggsFolly Sep 23 '16 at 14:26
-