3

I can't understand why I get the error:

Number of variables doesn't match number of parameters in prepared statement

My code looks like this:

$DB['con'] = new mysqli($$DB['host'],$DB['user'],$DB['pass'],$DB['base']);

$stmt=$DB['con']->prepare("insert into points(iduser,puncte,nume,email,telefon,ultimulpost)values('?',?,'?','?','?',(SELECT CURDATE()))");
$stmt->bind_param('sisss',$idm,$mynumber,$nume,$email,$tel);
$stmt->execute();
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

9

The problem is in this line:

$stmt=$DB['con']->prepare("insert into points(iduser,puncte,nume,email,telefon,ultimulpost)values('?',?,'?','?','?',(SELECT CURDATE()))");

Your mistake is that you are putting quote marks around the ? placeholders. This means that they are interpreted as a literal string ?, rather than as a placeholder that needs filling. You therefore only actually have one placeholder, so when you send five, it tells you you have the wrong number.

The quotes are unnecessary. The whole point of 'sisss' is to say "these values are strings", so you don't need to use the quotes to say the same thing.

The following should work:

$stmt=$DB['con']->prepare("insert into points(iduser,puncte,nume,email,telefon,ultimulpost)values(?,?,?,?,?,(SELECT CURDATE()))");
lonesomeday
  • 233,373
  • 50
  • 316
  • 318