我有一个registration.php页面和另一个registration_checker_page.php。
如果用户名和/或电子邮件在提交后被获取,那么它会将他们重定向回上一个(注册)页面。
但是随后他们填写的数据就会丢失。有没有办法在不清除数据的情况下重定向它们?
if(mysql_num_rows($queryUser) > 0){
echo '<p><div id="redirect"/></p>';
}
function redir {
code ... location.href = "registration.php";
}
编辑:通过填写的数据,它是名字、用户名、邮政编码等。但密码等其他信息将被删除。
最佳答案
您可以使用 session 或 cookie 来实现相同的目的
if(mysql_num_rows($queryUser) > 0){
echo '<p><div id="redirect"/></p>';
}
function redir() {
$userName = $_POST['username'];
$email = $_POST['email'];
setcookie("userName", $userName, time()+3600); /* expire in 1 hour */
setcookie("emial", $email, time()+3600);
code ... location.href = "registration.php";
}
在你的表格
<input type="text" name="userName" value="<?php echo isset($_COOKIE['userName']) ? $_COOKIE['userName']:'' ?>">
<input type="text" name="email" value="<?php echo isset($_COOKIE['email']) ? $_COOKIE['email']:'' ?>">
您可以使用 session 进行上述操作。
希望这会有所帮助
关于javascript - 将用户重定向回注册页面,但将其填写的表单保留在 php 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22441676/