2013-03-25 42 views
1

警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:無效的參數編號:綁定變量的數量不匹配用C令牌的數目:\瓦帕\ WWW \飛馬\類\上線generic.class.php 68
類Add_consum延伸通用{警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:

private $result; 
private $error; 
private $impexp; 
private $sea_air; 
private $customername; 
private $customerreference; 
private $homeconsumption; 
private $invoicevalue; 
private $currency; 
private $mbl_hbl; 
private $vesselname; 
private $lcl_fcl; 
private $noofcontainers; 
private $sft_containers; 
private $fcl_containerno; 
private $weight; 
private $noofpallets; 
private $itemdescripion; 
private $suppliersdetails; 
private $cif_fob; 
private $blnumer; 
private $bl_date; 

function __construct() { 

    if(isset($_POST['searchimpexp'])) { 
     $this->searchimpexp(); 
     exit(); 
    } 
// jQuery form validation 
    parent::checkExists(); 

    if(isset($_POST['add_consum'])) { 
     $this->impexp = parent::secure($_POST['impexp']); 
     $this->sea_air = parent::secure($_POST['sea_air']); 
     $this->customername = parent::secure($_POST['customername']); 
     $this->customerreference = parent::secure($_POST['customerreference']); 
     $this->homeconsumption = parent::secure($_POST['homeconsumption']); 
     $this->invoicevalue = parent::secure($_POST['invoicevalue']); 
     $this->currency = parent::secure($_POST['currency']); 
     $this->mbl_hbl = parent::secure($_POST['mbl_hbl']); 
     $this->vesselname = parent::secure($_POST['lcl_fcl']); 
     $this->lcl_fcl = parent::secure($_POST['customerreference']); 
     $this->noofcontainers = parent::secure($_POST['noofcontainers']); 
     $this->sft_containers = parent::secure($_POST['sft_containers']); 
     $this->fcl_containerno = parent::secure($_POST['fcl_containerno']); 
     $this->weight = parent::secure($_POST['weight']); 
     $this->noofpallets = parent::secure($_POST['noofpallets']); 
     $this->itemdescripion = parent::secure($_POST['itemdescripion']); 
     $this->suppliersdetails = parent::secure($_POST['suppliersdetails']); 
     $this->cif_fob = parent::secure($_POST['cif_fob']); 
     $this->blnumer = parent::secure($_POST['blnumer']); 
     $this->bl_date = parent::secure($_POST['bl_date']); 

     // Confirm all details are correct 
     $this->verify(); 

     // Create the user 
     $this->addconsum(); 

     if(!empty($this->error)) parent::displayMessage($this->error); 
      else echo $this->result; 
     exit(); 

    } 

} 

/** @todo: Should be in a different class, not add_consum. */ 
private function searchimpexp() { 

    if(empty($_POST['searchimpexp'])) return false; 

    $sql = array(':searchQ' => $_POST['searchimpexp'] . '%'); 
    $sql = "SELECT distinct username as suggest, user_id 
      FROM login_users 
      WHERE username LIKE :searchQ 
      OR name LIKE :searchQ 
      OR user_id LIKE :searchQ 
      ORDER BY username 
      LIMIT 0, 5"; 

    $stmt = parent::query($sql); 

    if ($stmt->rowCount() < 1) { 
     echo '<h3>' . _('No suggestions') . '</h3> 
       <p class="help-block">' . _('Try searching by username, name, or user id.') . '</p>'; 
     return false; 
    } 

    echo '<h2>' . _('Suggestions') . '</h2>'; 

    while($suggest = $stmt->fetch(PDO::FETCH_ASSOC)) 
     echo "<p><a href='users.php?uid=" . $suggest['user_id'] . "'>" . $suggest['suggest'] . "</a></p>\n"; 

} 

//返回一個值,如果它存在 公共職能getPost($ var){

if(!empty($this->$var)) { 
     return $this->$var; 
    } else return false; 

} 

private function verify() { 

    if(empty($this->impexp)) { 
     $this->error = '<div class="alert alert-error">'._('You must enter a impexp.').'</div>'; 
     return false; 
    } 

    if(empty($this->sea_air)) { 
     $this->error = '<div class="alert alert-error">'._('You must enter a seaair.').'</div>'; 
     return false; 
    } 

    if(empty($this->customername)) { 
     $this->error = '<div class="alert alert-error">'._('You must enter a customername.').'</div>'; 
     return false; 
    } 



} 

私有函數addconsum(){

if (!empty($this->error)) return false; 

    $params = array(
     ':impexp'   => $this->impexp, 
     ':sea_air'   => $this->sea_air, 
     ':customername'  => $this->customername, 
     ':homeconsumption' => $this->customerreference, 
     ':homeconsumption' => $this->homeconsumption, 
     ':invoicevalue'  => $this->invoicevalue, 
     ':currency'   => $this->currency, 
     ':mbl_hbl'   => $this->mbl_hbl, 
     ':vesselname'  => $this->vesselname, 
     ':lcl_fcl'   => $this->lcl_fcl, 
     ':noofcontainers' => $this->noofcontainers, 
     ':sft_containers' => $this->sft_containers, 
     ':fcl_containerno' => $this->fcl_containerno, 
     ':weight'   => $this->weight, 
     ':noofpallets'  => $this->noofpallets, 
     ':itemdescripion' => $this->itemdescripion, 
     ':suppliersdetails' => $this->suppliersdetails, 
     ':cif_fob'   => $this->cif_fob, 
     ':blnumer'   => $this->blnumer, 
     ':bl_date'   => $this->bl_date, 
    ); 

父::查詢(「INSERT INTO add_consignmentimpexpsea_aircustomernamecustomerreferencehomeconsumptioninvoicevaluecurrencymbl_hblvesselnamelcl_fclnoofcontainerssft_containersfcl_containerno,weight,noofpallets,itemdescripion,suppliersdetails, cif_fob,blnumer,bl_date)VALUES(:impe xp,:sea_air,:customername,:customerreference,:homeconsumption,:invoicevalue,:currency,:mbl_hbl,:vesselname,:lcl_fcl,:noofcontainers,:sft_containers,:fcl_containerno,:weight,:noofpallets,:itemdescripion,:suppliersdetails, :cif_fob,:blnumer,:bl_date);「,$ params); }

} $ addconsum = new Add_consum();

回答

0

你的問題似乎是,你是不是值綁定到你的查詢:

$stmt = parent::query($sql); 
$stmt->bindValue(':searchQ', $_POST['searchimpexp'], PDO::PARAM_STR); 
0

代碼:

$sql = array(':searchQ' => $_POST['searchimpexp'] . '%'); 
    $sql = "SELECT distinct username as suggest, user_id 
      FROM login_users 
      WHERE username LIKE :searchQ 
      OR name LIKE :searchQ 
      OR user_id LIKE :searchQ 
      ORDER BY username 
      LIMIT 0, 5"; 

    $stmt = parent::query($sql); 

只設置

$stmt = parent::query("SELECT distinct username as suggest, user_id 
       FROM login_users 
       WHERE username LIKE :searchQ 
       OR name LIKE :searchQ 
       OR user_id LIKE :searchQ 
       ORDER BY username 
       LIMIT 0, 5"); 

的設置數組的$ sql是無用的,因爲它被覆蓋了n $ sql設置select語句。

無效的參數編號:綁定變量的數量與令牌數量不匹配意味着查詢中變量的nr不是賦予給PDO對象的值的數量。我不確定函數parent :: query的作用,但應該使用prepare-statement。

你將不得不這樣做

<?php 

$statement = parent::query-prepare("SELECT distinct username as suggest, user_id 
        FROM login_users 
        WHERE username LIKE :searchQ 
        OR name LIKE :searchQ 
        OR user_id LIKE :searchQ 
        ORDER BY username 
        LIMIT 0, 5"); 
$statement->execute(array(':searchQ' => $_POST['searchimpexp'] . '%'));  
$row = $statement->fetchAll(); 

?> 
相關問題