我正在尝试创建一个用户可以更新其信息的页面,例如他们的姓名/电子邮件和密码。以下是更新功能:
public function update() {
$correct = false;
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "UPDATE users SET `username` = :username, `password` = :password, `name` = :name, `email` = :email WHERE `userID` = :userID";
$stmt = $con->prepare( $sql );
$stmt->bindValue( "username", $this->username, PDO::PARAM_STR );
$stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR );
$stmt->bindValue( "name", $this->name, PDO::PARAM_STR );
$stmt->bindValue( "email", $this->email, PDO::PARAM_STR );
$stmt->bindValue( "userID", $this->userID, PDO::PARAM_STR );
$stmt->execute();
print("PDO::FETCH_ASSOC: ");
print("Return next row as an array indexed by column name\n");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($result);
print("\n");
以下是页面上的表格:
<?php
echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
<ul>
<li>
<label for="usn">Name : </label>
<input type="text" id="usn" maxlength="36" required autofocus name="name" value="' . $row['name'] . '" />
<input type="text" name="userID" value="' . $row['userID'] . '" class="displaynone"/>
</li>
<li>
<label for="usn">Email : </label>
<input type="text" id="usn" maxlength="46" required autofocus name="email" value="' . $row['email'] . '" />
</li>
<li>
<label for="usn">Username : </label>
<input type="text" id="usn" maxlength="30" required autofocus name="username" disabled="disabled" value="' . $row['username'] . '" />
</li>
<li>
<label for="passwd">Password : </label>
<input type="password" id="passwd" maxlength="30" required name="password" />
</li>
<li>
<label for="conpasswd">Confirm Password : </label>
<input type="password" id="conpasswd" maxlength="30" required name="conpassword" />
</li>
<li class="buttons">
<input type="submit" name="update" value="Update" />
<input type="button" name="cancel" value="Cancel" />
</li>
</ul>
</form>';
$usr = new Users; //create new instance of the class Users
$usr->storeFormValues( $_POST ); //store form values //if the entered password is match with the confirm password then register him
if( $_POST['password'] == $_POST['conpassword'] ) {
echo $usr->update($_POST);
} else {
//if not then say that he must enter the same password to the confirm box.
echo "Password and Confirm password not match";
}
?>
这会返回以下错误:
PDO::FETCH_ASSOC: Return next row as an array indexed by column name SQLSTATE[HY000]: General error
我真的被困在这里了。我不知道如何进一步解决这个问题。