gpt4 book ai didi

php - 一个数据库可以工作,而第二个数据库则不能

转载 作者:行者123 更新时间:2023-11-29 19:26:30 25 4
gpt4 key购买 nike

我有一个数据库,其中有 4 个表,2 个用于私有(private)用户,2 个用于商业用户。由于某种原因,当我尝试使用业务用户的电子邮件登录时,它不起作用,但用户名起作用,并且在私有(private)表中它起作用,这是我的代码,如果我没有正确解释它,请告诉我,我会尽力解释再来一次

    $password = $_POST['password'];
$emailuser = $_POST['unameemail'];
$password = mysqli_real_escape_string($sql , $password);
$emailuser = mysqli_real_escape_string($sql , $emailuser);
$pwcheck = "
SELECT * FROM private AS p
INNER JOIN user_private_data
AS c ON p.id = c.id
WHERE username='$emailuser' OR email='$emailuser'"; // part that works fine
$resultcheck = mysqli_query($sql , $pwcheck); // part that works fine
$rowcheck = mysqli_fetch_array($resultcheck , MYSQLI_ASSOC); // part that works fine
$hash = $rowcheck['password']; // part that works fine
$hash_pwd = password_verify($password , $hash);
if ($hash_pwd != 0) {
$_SESSION['username'] = $rowcheck['username']; // part that works fine
$_SESSION['logged'] = true; // part that works fine
header("refresh:0;url=../blablabla.php"); // part that works fine
} else {
$privateuser = "
SELECT * FROM business AS d
INNER JOIN user_business_data
AS j ON d.id = j.id
WHERE username='$emailuser' OR email='$emailuser'"; // doesn't work
$resultprivate = mysqli_query($sql , $privateuser); // doesn't work
$rowprivate = mysqli_fetch_array($resultprivate , MYSQLI_ASSOC);
$hashprivate = $rowprivate['password'];
$hash_private = password_verify($password , $hashprivate);
if ($hash_private != 0) {

$_SESSION['username'] = $rowprivate['username'];
$_SESSION['logged'] = true;
$_SESSION['business'] = $rowprivate['bname'];
$_SESSION['type'] = 'business';
}

最佳答案

尝试一下:在获取之前您需要检查查询是否确实有结果我假设变量 $sql 在您的连接中定义

<?php

$password = $_POST['password'];
$emailuser = $_POST['unameemail'];
$password = mysqli_real_escape_string($sql, $password);
$emailuser = mysqli_real_escape_string($sql, $emailuser);
$pwcheck = "
SELECT * FROM private AS p
INNER JOIN user_private_data
AS c ON p.id = c.id
WHERE username='$emailuser' OR email='$emailuser'"; // part that works fine
$resultcheck = mysqli_query($sql, $pwcheck); // part that works fine
$rowcheck = mysqli_fetch_array($resultcheck, MYSQLI_ASSOC); // part that works fine
$hash = $rowcheck['password']; // part that works fine
$hash_pwd = password_verify($password, $hash);
if ($hash_pwd != 0) {
$_SESSION['username'] = $rowcheck['username']; // part that works fine
$_SESSION['logged'] = true; // part that works fine
header("refresh:0;url=../blablabla.php"); // part that works fine
} else {
$privateuser = "
SELECT * FROM business AS d
INNER JOIN user_business_data
AS j ON d.id = j.id
WHERE username='$emailuser' OR email='$emailuser'"; // doesn't work
$resultprivate = mysqli_query($sql, $privateuser); // doesn't work
if ($resultprivate->num_rows > 0) {
$rowprivate = mysqli_fetch_array($resultprivate, MYSQLI_ASSOC);
$hashprivate = $rowprivate['password'];
$hash_private = password_verify($password, $hashprivate);
if ($hash_private != 0) {

$_SESSION['username'] = $rowprivate['username'];
$_SESSION['logged'] = true;
$_SESSION['business'] = $rowprivate['bname'];
$_SESSION['type'] = 'business';
} else {
//no record
}
}
?>

关于php - 一个数据库可以工作,而第二个数据库则不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42092561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com