2

我创建了一个 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 之外没有人在搞乱。

4

1 回答 1

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'])));
于 2013-02-26T11:43:59.070 回答