function update() { $results = array(); $results['pageTitle'] = "Profile Update | Dating website"; $results['user'] = User::getById($_SESSION['userId']); if (isset($_POST['userId'])) { $user = new User($_POST); $user->id = $results['user']->id; if ($user->update()) { $results['successMessage'] = "Update successful."; $results['user'] = $user; } else { //echo User::errorInfo(); if (User::errorCode() == "ERR_INV_NAME") { $results['errorMessage'] = "Update unsuccessful, invalid name provided."; } else { if (User::errorCode() == "ERR_INV_PHONE") { $results['errorMessage'] = "Update unsuccessful, invalid phone number provided."; } else { $results['errorMessage'] = "Update unsuccessful. Please try again."; } } } } require TEMPLATE_PATH . "/updateForm.php"; }
public function updatePassword() { if (is_null($this->id)) { trigger_error("User::update(): Attempt to update a user object that does not have its ID property set.", E_USER_ERROR); } if (strlen($this->password) < MINIMUM_PASSWORD_LENGTH) { self::$errorCode = "ERR_INV_PASS"; return false; } //Update the object $this->password = Password::hash($this->password); $conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD); $sql = "UPDATE " . TABLENAME_USERS . " SET password=:password WHERE id = :id"; $st = $conn->prepare($sql); $st->bindValue(":password", $this->password, PDO::PARAM_STR); $st->bindValue(":id", $this->id, PDO::PARAM_INT); $st->execute(); $conn = null; return true; }