1

警告:PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: 绑定变量的数量与 C:\wamp\www\pegasus\classes\generic.class.php 中的标记数量不匹配在第 68 行
类 Add_consum 扩展通用 {

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";

}

// 如果存在则返回一个值 public function 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,
    );

parent::query("INSERT INTO add_consignment( impexp, 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值 (:impexp, :sea_air, :customername, :customerreference, :homeconsumption, :invoicevalue, :货币、:mbl_hbl、:vesselname、:lcl_fcl、:noofcontainers、:sft_containers、:fcl_containerno、:weight、:noofpallets、:itemdescripion、:suppliersdetails、:cif_fob、:blnumer、:bl_date);", $params); }

} $addconsum = 新的 Add_consum();

4

2 回答 2

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 是无用的,因为当 $sql 设置选择语句时它会被覆盖。

无效的参数编号:绑定变量的数量与标记的数量不匹配意味着查询中的 nr 个变量不是赋予 PDO 对象的值的数量。我不确定函数 parent::query 做了什么,但应该使用准备语句。

你将不得不做类似的事情

<?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();

?>
于 2013-03-25T06:46:03.337 回答
0

您的问题似乎是您没有将值绑定到您的查询:

$stmt = parent::query($sql);
$stmt->bindValue( ':searchQ', $_POST['searchimpexp'], PDO::PARAM_STR );
于 2013-03-25T06:11:06.387 回答