dongqiao1151 2015-06-29 20:31
浏览 21

没有错误,var转换看起来正确,不会插入

I was wondering if any one had any ideas on the meaning of this error

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens Database.php on line 95

lines 83 - 97 database.php

    ksort($data);

    //$fieldNames = implode(', ', array_keys($data));   /// to be tested
    $fieldNames = implode('`, `', array_keys($data));
    $fieldValues = ':' . implode(', :', array_keys($data));

    $sth = $WIdb->prepare("INSERT INTO $table (`$fieldNames`) VALUES ($fieldValues)");

    foreach ($data as $key => $value) {
        $sth->bindValue(":$key", $value);
    }

    $sth->execute();
    $sth->closeCursor();

my insert for db

$this->WIdb->insert("WI_Members", array(
            ":email"             => $user['email'],
            ":username"          => strip_tags($user['username']),
            ":password"          => $this->hashPassword($user['password']),
            ":full_name"       => strip_tags($user['full_name']),
            ":birthday"          => $full_birthday,
            ":gender"            => $user['gender'],
            ":country"           => $user['country'],
            ":confirmed"         => $confirmed,
            ":confirmation_key"  => $key,
            ":register_date"     => date("Y-m-d")     
        ));  

trying to re-code my site, to stop sql injection, its passed all validation,

i have done a VAR DUMP

["email"]=>
  string(21) "test@googlemail.com"
  ["username"]=>
  string(12) "warner"
  ["full_name"]=>
  string(6) "Jules "
  ["password"]=>
  string(128) "db0773097ac0e01005f698bc50488524f3bea68b545ad35aa8ac73ce5c3b447b82aebcab45763a650a9195caf11cf9e7fd3f6f67265f371702ef07128bb65cdf"
  ["confirm_password"]=>
  string(128) "db0773097ac0e01005f698bc50488524f3bea68b545ad35aa8ac73ce5c3b447b82aebcab45763a650a9195caf11cf9e7fd3f6f67265f371702ef07128bb65cdf"
  ["gender"]=>
  string(1) "m"
  ["birthmonth"]=>
  string(2) "02"
  ["birthday"]=>
  string(2) "22"
  ["birthyear"]=>
  string(4) "1980"
  ["country"]=>
  string(14) "United Kingdom"
  ["bot_sum"]=>
  string(2) "10"

i have looked over a few forums, i have tried a number of bits, nothing seems to work, and i have been awake 24 hours trying to fix this, so figured i would try here fresh might help lol

and thank you all for your time

  • 写回答

1条回答 默认 最新

  • dqwh1202 2015-06-29 20:38
    关注

    Your error means that the number of items in your query doesn't match the number of items in the value array.

    You are declaring a certain amount of parameters but the array with their value is not the same length.

    Check if they match and fix accordingly to solve the issue.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统