2017-11-09 22 views
-2

私のコードで何が問題であるかを調べるのに苦労しています。問題の解決には役に立たなかった。 SQLSTATE [HY093]:無効なパラメータ番号:パラメータがC:\ xampp \ htdocs \ Website system \ sale.phpのオンラインで定義されていませんでした。(警告:PDOStatement :: execute()正しい列がある:プレースホルダにバインドされている:「条件」が、あなたのbindValue機能で「prodCondition」60)PDOStatement :: execute():SQLSTATE [HY093]:パラメータ番号が無効です:パラメータが60行目で定義されていません

<?php 
     //link files 
     require ('config.php'); //database connection 

     //get user input from the form 
     if (isset($_POST['formSubmit'])) { 
      //product details 
      $brand = checkData($_POST['brand']); 
      $model = checkData($_POST['model']); 
      $serial = checkData($_POST['serialnumber']); 
      $yearModel = checkData($_POST['yearmodel']); 
      $productType = checkData($_POST['type']); 
      $condition = checkData($_POST['condition']); 
      //supplier details 
      $supplierId = checkData($_POST['supplierid']); 
      $supInvoice = checkData($_POST['supplierinvoice']); 
      $supPrice = checkData($_POST['supplierprice']); 
      //customer details 
      $custId = checkData($_POST['customerid']); 
      $custInvoice = ($_POST['custinvoice']); 
      $custPrice = checkData($_POST['custprice']); 
      $purchaseDate = checkData($_POST['purchasedate']); 

      require_once ('config.php'); //database connection 
      global $dbselect; 
      //SQL - add data to database 
      $qry1 = 'INSERT INTO product 
        (brand, model, serial, yearmodel, type, prodCondition, purchDate, supplierId, supInvoice, supPrice, custId, custInvoice, custPrice) 
        VALUES 
        (:brand, :model, :serial, :yearModel, :productType, :condition, :purchaseDate, :supplierId, :supInvoice, :supPrice, :custId, :custInvoice, :custPrice)'; 
      //execute query 
      $statement = $dbselect->prepare($qry1); 
      $statement->bindValue(':brand', $brand); 
      $statement->bindValue(':model', $model); 
      $statement->bindValue(':serial', $serial); 
      $statement->bindValue(':yearModel', $yearModel); 
      $statement->bindValue(':productType', $productType); 
      $statement->bindValue(':prodCondition', $condition); 
      $statement->bindValue(':purchaseDate', $purchaseDate); 
      $statement->bindValue(':supplierId', $supplierId); 
      $statement->bindValue(':supInvoice', $supInvoice); 
      $statement->bindValue(':supPrice', $supPrice); 
      $statement->bindValue(':custId', $custId); 
      $statement->bindValue(':custInvoice', $custInvoice); 
      $statement->bindValue(':custPrice', $custPrice); 

      if ($statement->execute()) { //////<-PROBLEM ON THIS LINE////// 
       echo 'New Sale Added Successfully!'; 
      } else { 
       echo 'Not successfull.'; 
      } 
      $statement->closeCursor(); 
     } 

     //validate data 
     function checkData($data) { 
      $data = trim($data); 
      $data = stripslashes($data); 
      $data = htmlspecialchars($data); 
      return $data; 
     } 
    ?> 
+1

は '置き換える:prodCondition':'とcondition'を。 –

+1

うわー!!どうもありがとうございます!出来た。私はそれが混乱していた、私は、VALUESは$なしで、フォームからデータを保持する変数でなければならないと思った。 –

答えて

0

プレースホルダを結合あなたのコラムをチェックしたり、コラム「prodConditionは」のバインドさパラメータプレースホルダを持っていますプレースホルダとして存在しません。列名とプレースホルダの一貫性を保つためには、読みやすくするために最善です。

だから、クエリービットは次のようになります。

 //SQL - add data to database 
     $qry1 = 'INSERT INTO product 
       (brand, model, serial, yearmodel, type, prodCondition, purchDate, supplierId, supInvoice, supPrice, custId, custInvoice, custPrice) 
       VALUES 
       (:brand, :model, :serial, :yearModel, :productType, :prodCondition, :purchaseDate, :supplierId, :supInvoice, :supPrice, :custId, :custInvoice, :custPrice)'; 
関連する問題