gpt4 book ai didi

PHP/MySQL 查询返回的结果不在数据库中

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

我正在尝试创建一个页面来检查您的登录信息是否正确。由于某种原因,当我回显从数据库中选择数据的结果查询时,我没有从数据库中获取应有的数据,我不确定它是什么数据。以下是页面上显示的内容:

Connected successfully
Resource id #3

这是我的 PHP 代码:

<?php
//start session
session_start();

//connect to MySQL Database
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';

// make members the current db
$db_selected = mysql_select_db('members_db', $con);
if (!$db_selected) {
die ('Can\'t use members database : ' . mysql_error());
}


$email = $_SESSION['email'];

$result = mysql_query("SELECT email,password FROM `members` WHERE 'email' = '$email'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

if ($email == $row[0] && $_SESSION['password'] == $row[1])
{
$_SESSION['loggedin']="YES";
$url= "Location: welcome.php";
header($url);
exit;
}

echo $result;

/*
//Problems:
$problem = "";
if ($email == $row[0] && $_SESSION['password'] != $row[1])
{
$problem = "invalidPassword";
}
if ($email != $row[0])
{
$problem = "InvalidUser";
}
$url = "Location: index.php?problem=$problem";
header($url);
exit;*/
?>

最佳答案

如果这有助于检查您是否获得了正确的数据,那么看起来您甚至没有进入验证用户的正确区域

 $row = mysql_fetch_row($result);
if ($email == $row[0] && $_SESSION['password'] == $row[1])
{

$_SESSION['loggedin']="YES";
$url= "Location: welcome.php";
header($url);
exit;
}
else //Validation failed
{

echo $row[0] . ' SESSION EMAIL ' . $email; //Which would echo the email that was returned and the email stored in the session, if they do not match it means the password was wrong.
}

关于PHP/MySQL 查询返回的结果不在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22799014/

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