简体   繁体   English

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

[英]PHP/MySQL Query returns results not in database

I'm trying to create a page that checks it you're login information in correct. 我正在尝试创建一个页面来检查您的登录信息是否正确。 For some reason, when I echo the results query that selects the data from the database, I don't get the data I should from the database, I'm not sure what data it is. 出于某种原因,当我回显从数据库中选择数据的结果查询时,我没有从数据库中获得应有的数据,我不确定它是什么数据。 Here's what shows on the page: 这是页面上显示的内容:

Connected successfully
Resource id #3

Here's my php code: 这是我的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;*/
?>

Here if this helps to check if you are getting the right data, it doesn't look like you are even getting into the right area where the user is validated 在这里,如果这有助于检查您是否获得了正确的数据,则看起来您甚至没有进入验证用户的正确区域

 $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.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM