0

i am still a beginner in web developing and we were asked to make a simple website with a login and a database , however i am facing a problem in a sql query on the sign in page , here's my code :

<?php
$data_src=new PDO("mysql:host=localhost;dbname=mini_projet",'root','');
$req = $data_src->prepare('INSERT INTO utilisateur values(:identifiant,:nom,:prénom,:email,:motdp)');
$req->execute(array(
'identifiant'=>$_POST['id'],
'nom'=>$_POST['nom'],
'prénom'=>$_POST['prenom'],
'email'=>$_POST['email'],
'motdp'=>$_POST['pwd']));
echo '<a href="forum.php">vous avez inscrit avec sucée cliquez ici</a>';
?>

and after i submit the information on the sign in page, i get this error :

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\wamp64\www\chat\inscri.php on line 9

'motdp'=>$_POST['pwd'] seems to be causing this problem but i can't figure what's wrong , the database and the web page are both fine.

  • I have my money on the (unknown) HTML form. I'll take that 50 to 1 odds, how about you boys? That, and/or `identifiant` is an AI'd column. – Funk Forty Niner May 01 '16 at 01:22
  • possible duplicate of [PHP: “Notice: Undefined variable” and “Notice: Undefined index”](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Funk Forty Niner May 01 '16 at 01:24
  • 1
    So in order to leave all the guesswork out of your question, post both your HTML form and db schema. Because that's all it is right now, "guesswork". You have been given answers, so see those. TBH, I highly doubt it. – Funk Forty Niner May 01 '16 at 01:29

1 Answers1

0

I would suggest that you list the columns being inserted. In fact, always use column lists with insert:

INSERT INTO utilisateur(identifiant, nom, prénom, email, motdp) 
    VALUES (:identifiant, :nom, :prénom, :email, :motdp);

I am guessing that the names of the columns are the same as the names of the variables.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • As long as the order of the columns are correct, there shouldn't be an issue not listing the columns. However, doing so does make it harder to future changes/debug to have them. – Aziz Saleh May 01 '16 at 01:08
  • 1
    @AzizSaleh . . . It is just a bad habit that should be avoided. – Gordon Linoff May 01 '16 at 01:41
  • i solved it XD , the problem was the "é" in prénom , when i renamed it in the database and in the querry to simply "prenom" it worked !! – Amine Tlili May 01 '16 at 21:35