绑定变量的数量与令牌的数量不匹配

时间:2013-02-26 11:41:49

标签: php mysql

我创建了一个将页面保存到数据库中的php页面,这是我写的代码:

try
    {
        $bdd = new PDO('mysql:host=localhost;dbname=tp_js_php','root','');
    }
    catch(PDOException $e)
    {
        die($e->getMessage());
    }

    //Selectionner la table de clients
          $reponse = $bdd->query('Select * from client');
          $clients = $reponse->fetchAll();

try
            {
            $req = $bdd->prepare('INSERT INTO client(nomClient,PrenomClient,Adresse,Télephone,Email,Pseudo,MotDePasse) VALUES (:nom, :prenom, :adresse, :tel, :email, :pseudo, :mdp)');
            $req->execute(array(
                    ':nom' => $_POST['nom'],
                    ':prenom', $_POST['prenom'],
                    ':adresse', $_POST['adresse'],
                    ':tel', $_POST['telephone'],
                    ':email', $_POST['email'],
                    ':pseudo', $_POST['pseudo'],
                    ':mdp', sha1($_POST['mdp'])));
        }
        catch(PDOException $e)
        {
            die($e->getMessage());
        }

这是我得到的错误:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\tp_fomulaire_js\insertion.php on line 21

第21行是:':mdp', sha1($_POST['mdp'])));

我计算所有的参数,除了idClient是增量的,没有人搞乱。

1 个答案:

答案 0 :(得分:3)

使用此代码,您必须使用=>,但您使用了,

$req->execute(array(
                ':nom' => $_POST['nom'],
                ':prenom' => $_POST['prenom'],
                ':adresse' => $_POST['adresse'],
                ':tel' => $_POST['telephone'],
                ':email' => $_POST['email'],
                ':pseudo' => $_POST['pseudo'],
                ':mdp' => sha1($_POST['mdp'])));