2016-09-23 18 views
-1
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 
    ); 
} 
+0

看起來你的查詢有錯誤... –

+0

第13行是**哪一行?** – RiggsFolly

+0

@RiggsFolly應該是一個帶有bind_param的對象。 –

回答

2

你有$con->prepare錯誤,因此它已經返回false,因此bind_param已失敗,因爲它不在mysqli_statement對象上工作。

嘗試從準備中的VALUES子句中刪除?之一,因爲您告訴mysql將11個參數插入到10個列名中。

+0

我已經刪除了一些字段,但它不工作。 $ con = new mysqli(「localhost」,「root」,「」,「electronicsshop」); (',?,'product_branding','product_type','product_description',product_price,number,reservefee,'status','image')。 ,?,?,?,?,?,?,?)「); $ sth-> bind_param('ssssiiisb',$ product_name,$ product_brand,$ product_type,$ product_description,$ product_price,$ number,$ reservefee,$ status,$ image); $ sth-> execute(); –

+1

@MurithiH隨機改變事物並不是解決方案。對你正在做的事情應用一點邏輯 – RiggsFolly

+1

現在你有10個列名和9個'''參數**它的簡單數學!** – RiggsFolly

相關問題