Javascript if 语句上弹出框

发布于 2024-11-26 20:05:36 字数 1170 浏览 0 评论 0原文

我的代码如下:

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡Ms空城旧梦 2024-12-03 20:05:36

在你的注册页面的某个地方:

<?php if(isset($_SESSION['ERROR']) && $_SESSION['ERROR']) { ?>
<script type = 'text/javascript'>
//<!--
   alert("I am an error Message.");
//-->
</script>
<?php } ?>

当然,如果JS被禁用,它就不起作用。您也可以添加 noscript 标记,并至少以相同的方式显示错误消息。

Somewhere in your register page:

<?php if(isset($_SESSION['ERROR']) && $_SESSION['ERROR']) { ?>
<script type = 'text/javascript'>
//<!--
   alert("I am an error Message.");
//-->
</script>
<?php } ?>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文