我的代码如下:
//Input Validations
$result = mysql_query("SELECT * FROM members WHERE `email` = '$insp_email' LIMIT 1" );
$exist = mysql_fetch_row($result);
if ($exist !==false ) {
$errmsg_arr[] = 'That Email is already registered.';
$errflag = true;
}
$result = mysql_query("SELECT * FROM members WHERE `login` = '$user_name' LIMIT 1" );
$exist = mysql_fetch_row($result);
if ($exist !==false ) {
$errmsg_arr[] = 'That Username is already registered.';
$errflag = true;
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
$_SESSION['ERROR'] = 'Yes';
session_write_close();
header("location: accountinfo.php");
exit();
}
如果注册页面中有任何输入验证,则用户将被引导回注册页面。我想要做的是当它们被重定向回来时,$ _SESSION ['ERROR']将= True。当且仅当为= True时,是否需要弹出框才能显示错误消息。我是弹出消息的代码。我只是无法弄清楚如何只在if $ _SESSION ['ERROR'] =='True'上加载它
<script language="javascript">
alert('<?= $s ?>')
</script>
该代码将显示带有php变量的消息。我需要帮助才能在$ _SESSION ['ERROR']等于'True'时显示消息
谢谢!
答案 0 :(得分:1)
在您的注册页面的某处:
<?php if(isset($_SESSION['ERROR']) && $_SESSION['ERROR']) { ?>
<script type = 'text/javascript'>
//<!--
alert("I am an error Message.");
//-->
</script>
<?php } ?>
当然,如果禁用JS,它将无效。您也可以添加一个noscript标记,并至少以相同的方式显示错误消息。