PHP中后续操作的问题(警报消息和标题)
我正在用PHP进行注册操作,需要在完成此操作后将用户重定向到另一个页面之前放置一条警告消息,但每当我放置PHP中后续操作的问题(警报消息和标题),php,html,delay,Php,Html,Delay,我正在用PHP进行注册操作,需要在完成此操作后将用户重定向到另一个页面之前放置一条警告消息,但每当我放置header(),它都只重定向到没有任何消息的位置 如何解决这个问题 if ($conn->query($query1)== TRUE) {header("Location:signupend.php"); ;} else die('Err
header()
,它都只重定向到没有任何消息的位置
如何解决这个问题
if ($conn->query($query1)== TRUE) {header("Location:signupend.php");
;}
else die('Error with the connection' .$conn->error);
//Send alert message with the following text during validation
} else {echo '<script language="javascript">';
echo 'alert("Please repeat your password correctly")';
echo '</script>';};
} else {echo '<script language="javascript">';
echo 'alert("Your password must be 4 to 31 characters long")';
echo '</script>';};
} else {echo '<script language="javascript">';
echo 'alert("Sorry, but this E-mail is already registered")';
echo '</script>';};
} else {echo '<script language="javascript">';
echo 'alert("Please fill all the fields")';
echo '</script>';};
?>
if($conn->query($query1)==TRUE){header(“Location:signupend.php”);
;}
else die('Error with the connection'.$conn->Error);
//在验证期间发送带有以下文本的警报消息
}else{echo';
回显“警报”(“请正确重复您的密码”);
回声“;};
}else{echo';
回显“警报”(“您的密码长度必须为4到31个字符”);
回声“;};
}else{echo';
回显“警报”(“抱歉,此电子邮件已注册”);
回声“;};
}else{echo';
回显“警报”(“请填写所有字段”);
回声“;};
?>
因为必须首先运行header
函数(意思是在页面呈现html之前),所以我认为您不能在设置header
重定向到其他页面之前发出警报。但我认为你能做到。不要使用php进行重定向,而是使用Javascript
if ($conn->query($query1)== TRUE) {
echo '<script>';
echo 'alert('....');'; // put your message here
echo 'window.location.replace("'.$_SERVER['REQUEST_URI'].'/signupend.php");'; // redirect to page you want
echo '</script>';
die(); // die here so it will stop executing the function below
}
if($conn->query($query1)==TRUE){
回声';
echo“alert(“…”);“;//将您的消息放在这里
echo'window.location.replace(“.$\u SERVER['REQUEST\u URI'.../signupend.php”);//重定向到所需页面
回声';
die();//在此处执行die,这样它将停止执行下面的函数
}
希望它能有所帮助您的代码很有用,而且确实有效,但现在重定向后,它会显示最后一条验证警报消息,并显示一个空白页