mysqli_stmt :: bind_param () [mysqli-stmt.bind-param]: Die Anzahl der Variablen entspricht nicht der Anzahl der Parameter

Mein PHP-Formular fügt ein paar Spalten und ein verschlüsseltes Passwort in meine Tabelle ein. Wenn ich es jedoch starte, heißt es, dass die Variablennummer nicht mit der Anzahl der Parameter übereinstimmt. Das ist mein Code:

<?php
if (isset($_POST['insert'])) {
require_once 'login.php'; 

  $OK = false;
  $conn = new mysqli ($host, $user, $password, $database) or die("Connection Failed");
  $stmt = $conn->stmt_init();


  $sql = 'INSERT INTO users (user_email, user_name, user_pref, user_password)
          VALUES(?, ?, ?, des_encrypt(substring(md5(rand()),1,8)))';
  if ($stmt->prepare($sql)) {
    // bind parameters and execute statement
    $stmt->bind_param('ssss', $_POST['user_email'], $_POST['user_name'], $_POST['user_pref'], $_POST['user_password']);
    // execute and get number of affected rows
    $stmt->execute();
    if ($stmt->affected_rows > 0) {
      $OK = true;
    }
  }
  if ($OK) {
    header('Location: confirm.php');
    exit;
  } else {
    $error = $stmt->error;
  }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Add User</title>
</head>

<body>
<h1>Add User</h1>
<?php if (isset($error)) {
  echo "<p>Error: $error</p>";
} ?>
<form id="form1" method="post" action="">
  <p>
    <label for="user_email">User email:</label>
    <input name="user_email" type="text" class="widebox" id="user_email">
  </p>
    <p>
    <label for="user_name">User name:</label>
    <input name="user_name" type="text" class="widebox" id="user_name">
  </p>
    <p>
    User role: <select name = "user_pref">
    <option value = "BLU">Blue</option>
    <option value = "YEL">Yellow<option>
    <option value = "GRE">GREEN</option>
    </select>
</p>
  <p>
    <input type="submit" name="insert" value="Register New User" id="insert">
  </p>
</form>
</body>
</html>

Wenn ich das Formular ohne ENCRYPTED PASSWORD teste, funktioniert es einwandfrei. Diese Zeile verursacht Probleme, wenn ich versuche, das Passwort einzugeben:

$stmt->bind_param('ssss', $_POST['user_email'], $_POST['user_name'], $_POST['user_pref'], $_POST['user_password']);

Soll ich den String für das Passwort in einen anderen ändern?

Vielen Dank

Antworten auf die Frage(3)

Ihre Antwort auf die Frage