Javascript if 语句上弹出框
我的代码如下:
//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' 时显示消息
谢谢!
My code is as follows:
//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();
}
If there are any input validations from the registration page, the user will be directed back to the registration page. What I want to do is when they are redirected back, $_SESSION['ERROR'] will = True. When and only when that is = True, do I want a popup box to display a error message. I the code for the popup message. I just can't figure out how to get it to load only on the if $_SESSION['ERROR'] == 'True'
<script language="javascript">
alert('<?= $s ?>')
</script>
That code will display a message with a php variable. I need help getting the message to display only when the $_SESSION['ERROR'] equals 'True'
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的注册页面的某个地方:
当然,如果JS被禁用,它就不起作用。您也可以添加 noscript 标记,并至少以相同的方式显示错误消息。
Somewhere in your register page:
Of course, it won't work if JS is disabled. You could add in a noscript tag as well and at least display the error message in the same fashion.