Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.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
Php 试图从两个数据库中读取以检查帐户是否存在_Php_Sql_Mysqli - Fatal编程技术网

Php 试图从两个数据库中读取以检查帐户是否存在

Php 试图从两个数据库中读取以检查帐户是否存在,php,sql,mysqli,Php,Sql,Mysqli,我正在尝试创建一个登录系统,根据他们的信息存储在哪个数据库中加载不同的主页-无论他们是客户还是企业 我已经创建了我的注册,当我尝试只检查一个数据库时,它会成功地将它们登录 不过,我不确定第二个数据库的这段代码放在哪里——每当我把它放在某个地方时,我总是收到错误,我在第一个数据库中使用了类似的代码 mysqli_stmt_bind_param($stmt2, "s", $ema); mysqli_stmt_execute($stmt2);

我正在尝试创建一个登录系统,根据他们的信息存储在哪个数据库中加载不同的主页-无论他们是客户还是企业

我已经创建了我的注册,当我尝试只检查一个数据库时,它会成功地将它们登录

不过,我不确定第二个数据库的这段代码放在哪里——每当我把它放在某个地方时,我总是收到错误,我在第一个数据库中使用了类似的代码

mysqli_stmt_bind_param($stmt2, "s", $ema);
                mysqli_stmt_execute($stmt2);
                $result2 = mysqli_stmt_get_result($stmt2);
这是完整的代码

} elseif (!empty($ema) AND !empty($pas)) {
            $sql1 = "SELECT * FROM users1 WHERE email1=?;";
            $sql2 = "SELECT * FROM users2 WHERE email2=?;";
            $stmt1 = mysqli_stmt_init ($conn);
            $stmt2 = mysqli_stmt_init ($conn1);
            //Check if there was an error reading data from database
            if (!mysqli_stmt_prepare($stmt1, $sql1) AND !mysqli_stmt_prepare($stmt2, $sql2)) {
                header("Location: ../splash.php?error=sqlerror");
} else {
                mysqli_stmt_bind_param($stmt1, "s", $ema);
                mysqli_stmt_execute($stmt1);
                $result1 = mysqli_stmt_get_result($stmt1);

                if($row1 = mysqli_fetch_assoc($result1)) {
                    $pwdcheck1 = password_verify($pas, $row1['pwd1']);

                    if($pwdcheck1 == false) {
                        header("Location:../splash.php?error=wrongdetails");
                        exit();
                    //If a username and password in the business account correlate, then load the business index.
                    } elseif ($pwdcheck1 == true){
                        session_start();
                        $_SESSION['userlog1'] = $row1['idUsers1'];
                        header("Location: ../../b/index1.php?login=success");
                        exit();
                    }

                } elseif ($row2 = mysqli_fetch_assoc($result2)) {
                    $pwdcheck2 = password_verify($pas, $row2['pwd2']);

                    if($pwdcheck2 == false) {
                        header("Location: ../splash.php?error=wrongdetails");
                        exit();
                    } elseif ($pwdcheck2 == true) {
                        session_start();
                        $_SESSION['userlog2'] = $row2['idUsers2'];
                        header("Location: ../../t/index2.php?login=success");
                        exit();
                    }
                }
            }
        } else {
            header("Location: ../splash.php?error=usernotfound");
        }


谢谢

事实上,你应该有一个单一的用户表,问题来自于众多的条件,每一个都是无用的

基本上,如果需要从两个查询中获得结果,那么应该立即逐个执行它们。没有任何中间条件

现在您可以检查密码了

if(($row && password_verify($pas, $row['pwd'])) {
    // OK
} else {
    // not OK
}

首先,为什么有两个用户表?应该只有一个表你只需要有一个登录表,也许表中有一列说明应该是哪种类型的登录,因为它把我所有的东西都改成了一个数据库-我是一个过分复杂的白痴。谢谢
if(($row && password_verify($pas, $row['pwd'])) {
    // OK
} else {
    // not OK
}