Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript警报正在打开一个PHP包含文件,而不是停留在主页上_Javascript_Php_Alert - Fatal编程技术网

Javascript警报正在打开一个PHP包含文件,而不是停留在主页上

Javascript警报正在打开一个PHP包含文件,而不是停留在主页上,javascript,php,alert,Javascript,Php,Alert,主页是index.php,它包含一个用于创建用户登录块的不同边栏_signin_block.php文件的include。在侧边栏中,如果登录成功,我将使用此javascript将它们发送到登录成功启动页:echo窗口。打开“login-success.php”,“self”}另一方面,如果登录失败,我有一个else语句,其中包含一个javascript,用于一个如下的警报框:echo alert“电子邮件或密码不正确,请重试” 这是我需要帮助的问题。而在index.php页面上,如果登录成功或失

主页是index.php,它包含一个用于创建用户登录块的不同边栏_signin_block.php文件的include。在侧边栏中,如果登录成功,我将使用此javascript将它们发送到登录成功启动页:echo窗口。打开“login-success.php”,“self”}另一方面,如果登录失败,我有一个else语句,其中包含一个javascript,用于一个如下的警报框:echo alert“电子邮件或密码不正确,请重试”

这是我需要帮助的问题。而在index.php页面上,如果登录成功或失败,则会打开包含的文件sidebar_signin_block.php并显示网页。我想停留在主页index.php上,不想打开侧栏_signin_block.php页面。如有任何建议,将不胜感激

以防万一,您需要它来诊断,我在下面包含了整个sidebar-sign-block.php文件:

<?php
session_start();
?>

<html>
<body>
<form method="post" action="sidebar-signin-block.php">

        <table width="90%" border="0" align="center" bgcolor="white">


            <tr>
                <td bgcolor="ffffff" colspan="2" align="center"><h2>User Login</h2></td>
            </tr>

            <tr>
                <td align="right">Email:</td>
                <td><input type="text" name="email"></td>
            </tr>

            <tr>
                <td align="right">Password:</td>
                <td><input type="password" name="password"></td>
            </tr>

            <tr>
                <td colspan="2" align="center"><input type="submit" name="login" value="Login"></td>

            </tr>

            <tr>
                <td colspan="2" align="center"><h3 style="margin-top:7px;"><a href="nonadmin_user_forgot_password.php" target="_blank" title="Reset Your Lost Password">Forgot Password?</a></h3></td>
            </tr>


            <tr>
                <td bgcolor="#ffffff" colspan="2" align="center"><div style="padding-top:5px;"><span style="font-size:20px;">Don't have an account?<br /><a href="/includes/register-user.php" title="Register with us!" target="_self">Sign Up</a> is <em>quick</em> and <em>easy</em>!</span></div></td>

        </table>
    </form>

    <?php 

// Connecting to the database and making the Bcrypt functions available
include("admin/includes/connect.php");
include ("lib/password.php");

// Gathering and sanitizing user login input
if(isset($_POST['login'])){

    $email = trim(((isset($conn) && is_object($conn)) ? mysqli_real_escape_string($conn, $_POST['email']) :((trigger_error  ("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "")));

        $pass = trim(((isset($conn) && is_object($conn)) ? mysqli_real_escape_string($conn, $_POST['password']) : ((trigger_error   ("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "")));

         // Checking the database records for the user login input
        $hash_query = "select nonadmin_user_pass from nonadmin_user_login where email='$email'";{
                $run_query = mysqli_query($conn, $hash_query);}
                while ($row = mysqli_fetch_assoc($run_query)) {
                $fetch_pass = $row['nonadmin_user_pass'];
                    }
        // If the user email and password matches we start a session                               
        if ((password_verify($pass, $fetch_pass)) == 1){

              // Verifying user login success with splash page then sending user back to the home page
              $_SESSION['email']=$email;
              echo "<script>window.open('login-success.php','_self')</script>";}
    // When the user login fails an alert is given to inform them
    else {
    echo "<script>alert('Email or password is incorrect please try again')</script>";
    echo "<script>window.open('index.php','_self')</script>";}
}
?>
</body>
</html>

检查用户是否已登录index.php,如何

    <?php
    session_start();
    //in sidebar position, do checking
    if(isset($_SESSION['email']) && $_SESSION['email'] != '')
    {
        //if user already login succesfully, do anything here
    } else {
        //if user not yet login, display side bar
        include 'sidebar-signin-block.php
    }
    //your next index.php code
登录表单的目标操作属性指向侧栏文件。因此,当用户按下submit按钮时,浏览器请求该页面并将其加载到当前帧中


为了避免这种情况,向表单添加一个提交事件处理程序,该处理程序使用AJAX将表单数据发送到服务器,然后返回false。这将抑制加载表单目标的正常浏览器行为。AJAX响应应该指出登录是成功还是失败,此时您可以加载启动页面或显示警报(视情况而定)。

Bro,不是java,而是javascriptHudixt感谢您指出这一点。我编辑了帖子并删除了两个单词之间的空格。我在谈论标签和标题,你在那里写了javaHudixt再次感谢你的输入,我修复了标题和标签。user4496955谢谢你的回答。在index.php代码中,我是这样做的:它似乎工作正常,如果记录或未记录,则显示include。当我尝试您提供的代码示例时,它停止工作,由于某种原因我无法注销。@我不明白为什么我的代码示例在注销过程中遇到问题。感谢您的反馈用户4496955非常欢迎您!我非常感谢用户在这里为帮助像我这样的人所付出的辛勤工作。这是一个极其宝贵的资源,值得它的重量在黄金!我在这里学到了很多知识,也解决了很多问题,这都归功于很多人在这个网站上的贡献-谢谢你的回答,我感谢你的帮助。我不熟悉AJAX,所以我将对此进行研究,看看是否可以实现您的解决方案。