如何在用户编辑名字和姓氏后刷新会话变量,它们会立即显示?现在,我需要注销并再次登录,以便我可以看到输入的更改,因为会话重新启动,对吧? 我该怎么办?阿贾克斯?角?我真的迷路了。我需要你的指导。谢谢!!
这是edit.php中的表单:
<form method="post" action="edit.php" name="user_edit_first_last_name" >
<label for="user_first_name"><?php echo WORDING_NEW_FIRST_NAME; ?></label>
<input id="user_first_name" type="text" name="user_first_name" value = "<?php echo $_SESSION['user_first_name']; ?>" required />
<label for="user_last_name"><?php echo WORDING_NEW_LAST_NAME; ?></label>
<input id="user_last_name" type="text" name="user_last_name" value = "<?php echo $_SESSION['user_last_name']; ?>" required />
<input type="submit" name="user_edit_first_last_name_submit" value="<?php echo WORDING_CHANGE_FIRST_LAST_NAME; ?>" />
</form><hr/>
这是另一个名为login.php的php文件,其中代码所在:
按下提交按钮时调用该函数:
}elseif(isset($_POST["user_edit_first_last_name_submit"])){
$this->editUserFirstLastName($_POST['user_first_name'], $_POST['user_last_name']);
}
开展业务的实际功能:
public function editUserFirstLastName($user_first_name, $user_last_name){
// prevent database flooding
$user_first_name = substr(trim($user_first_name), 0, 64);
$user_last_name = substr(trim($user_last_name), 0, 64);
$result_row = $this->getUserData($_SESSION['user_name']);
$user_name = $_SESSION['user_name'];
$query_edit_user_first_last_name = $this->db_connection->prepare("UPDATE users SET user_first_name = :user_first_name, user_last_name = :user_last_name WHERE user_name = :user_name");
$query_edit_user_first_last_name->bindValue(':user_first_name', $user_first_name, PDO::PARAM_STR);
$query_edit_user_first_last_name->bindValue(':user_last_name', $user_last_name, PDO::PARAM_STR);
$query_edit_user_first_last_name->bindValue(':user_name', $user_name, PDO::PARAM_STR);
$query_edit_user_first_last_name->execute();
}
答案 0 :(得分:1)
只需在editUserFirstLastName
中设置会话值