スクリプトのこの部分は、複数のユーザー名をチェックします。ユーザーが存在するというエラー メッセージで終わるのではなく、見つかったユーザーを更新する必要があります。
// Verify a users existance by username. Function will fail if multiple usernames are encountered.
function userExists( $username )
{
// set up prepared statement
$stmt = $this->conn->prepare("SELECT * FROM $this->table WHERE $this->username_column = ?");
// bind the parameters
$stmt->bind_param("s", $username);
// execute prepared statement
if(!$stmt->execute())
{
$this->lastError = "Error in ".__FUNCTION__.": Username provided has more then one (".$stmt->num_rows().") records associated with it where there should only be one record.";
return false;
}
$stmt->store_result();
// check to make sure a username doesn't have duplicate usernames
if($stmt->num_rows() == 0)
{
$this->lastError = "Error in ".__FUNCTION__.": Username provided has more then one (".$stmt->num_rows().") records associated with it where there should only be one record.";
return false;
}
// return indicating success
return true;
}
これが回答を支援するために必要かどうかはわかりませんが、スクリプトのこの部分は、データベースに新しいユーザーを追加するために使用されます。
function addUser( $username, $password )
{
// encrypt password if set (default == enabled w/ sha1)
if($this->use_encryption)
$password = ($_SESSION['password']);
$salt = "CHANGE-SALT";
// Add some salt to the users password.
$salt .= $password; // The password is salted
$password = $salt; // Change the password var to contain our new salted pass.
$password = md5($password);
if($this->userExists( $username ))
die("ERROR USER EXISTS");
// create sql
$sql = "INSERT INTO $this->table ( $this->username_column , $this->password_column) VALUES (?, ?)";
// set up prepared statement
$stmt = $this->conn->prepare($sql);
// bind the parameters
$stmt->bind_param("ss", $username, $password);
// execute prepared statement
if(!$stmt->execute())
{
$this->lastError = "Error in ".__FUNCTION__.": Supplied user/pass fields cannot be added.";
return false;
}
return true;
}
事前に感謝します。
トレバー