3

This is my Error:

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /Applications/XAMPP/xamppfiles/htdocs/Jil/benutzer_eintragen.php on line 19

and this is my Code

$sql = "INSERT INTO benutzer SET vorname='?', nachname='?', username='?', email='?', passwort='?';";
$stmt = $db->prepare($sql);
$stmt->bind_param("sssss", $vorname, $nachname, $username, $email, $passwort);
$stmt->execute();
George Cummins
  • 28,485
  • 8
  • 71
  • 90
Rafael Marques
  • 797
  • 1
  • 8
  • 18

2 Answers2

6

I think you need to eliminate the quote marks in the statement:

$sql = "INSERT INTO benutzer SET vorname=?, nachname=?, username=?, email=?, passwort=?;";
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
2

You don't need the quotes around the ? in the SQL statement.

Also, your SQL statement is incorrect. SET is only used with UPDATE, INSERT uses VALUES.

$sql = "INSERT INTO benutzer(vorname,nachname,username,email,passwort) VALUES (?,?,?,?,?)";

$sql = "INSERT INTO benutzer SET vorname=?, nachname=?, username=?, email=?, passwort=?";
$stmt = $db->prepare($sql);
$stmt->bind_param("sssss", $vorname, $nachname, $username, $email, $passwort);
$stmt->execute();
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • 1
    According to [this answer](http://stackoverflow.com/questions/861722/mysql-insert-into-table-values-vs-insert-into-table-set#861729), the `INSERT INTO ... SET` syntax is valid for MySQL. – George Cummins Jul 13 '11 at 17:40
  • 2
    @George: I did not know that. Learn something new every day :-) – gen_Eric Jul 13 '11 at 17:43