Log.php 返回“无效用户”来自 MySQL 数据库

发布于 2024-11-06 16:00:38 字数 1266 浏览 0 评论 0原文

我正在本地计算机上托管一个网站(在 Mac 上使用 MAMP Pro),并且需要将托管切换到另一台本地 Mac。我已经复制了网站的所有文件和 MySQL 表,并检查服务器和 MySQL 是否运行正常。一切似乎都很好,除了当我尝试登录时登录系统返回“无效用户”,即使我输入了正确的用户信息(我已经尝试了一些用户只是为了确定)。

处理登录的 log.php 看起来像这样:

<?
session_name("MyLogin");
session_start();

if($_GET['action'] == "login") {
$conn = mysql_connect("localhost","root","password"); // your MySQL connection data
$db = mysql_select_db("nick"); //put your database name in here 
$name = $_POST['user'];
$q_user = mysql_query("SELECT * FROM USERS WHERE login='$name'");

if(mysql_num_rows($q_user) == 1) {

$query = mysql_query("SELECT * FROM USERS WHERE login='$name'");
$data = mysql_fetch_array($query);
if($_POST['pwd'] == $data['password']) { 
$_SESSION["name"] = $name;
header("Location: http://monthlymixup.com/may.php"); // success page. put the URL you want 
exit;
} else {
header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
exit;
}
} else {
header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
exit;
}
}

// if the session is not registered
if(session_is_registered("name") == false) {
header("Location: login.php");
}

?>

我已经暂时删除了上面代码中的密码。

我想知道我可以采取什么步骤来解决这个问题,如果有任何帮助,我将不胜感激。

谢谢,

尼克

I am hosting a website from a local computer (using MAMP Pro on a Mac), and need to switch the hosting to another local Mac. I have copied across all of the files for my website, and the MySQL tables, and checked that the server and MySQL are running OK. Everything seems to be fine, except that the login system is returning "Invalid User" when I try to log in, even though I am entering the correct user info (I have tried a few users just to be sure).

The log.php that handles the login looks like this:

<?
session_name("MyLogin");
session_start();

if($_GET['action'] == "login") {
$conn = mysql_connect("localhost","root","password"); // your MySQL connection data
$db = mysql_select_db("nick"); //put your database name in here 
$name = $_POST['user'];
$q_user = mysql_query("SELECT * FROM USERS WHERE login='$name'");

if(mysql_num_rows($q_user) == 1) {

$query = mysql_query("SELECT * FROM USERS WHERE login='$name'");
$data = mysql_fetch_array($query);
if($_POST['pwd'] == $data['password']) { 
$_SESSION["name"] = $name;
header("Location: http://monthlymixup.com/may.php"); // success page. put the URL you want 
exit;
} else {
header("Location: login.php?login=failed&cause=".urlencode('Wrong Password'));
exit;
}
} else {
header("Location: login.php?login=failed&cause=".urlencode('Invalid User'));
exit;
}
}

// if the session is not registered
if(session_is_registered("name") == false) {
header("Location: login.php");
}

?>

I have temporarily removed the password in the above code.

I wonder what steps I can take to troubleshoot this issue, and would be grateful for any help.

Thanks,

Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除→记忆 2024-11-13 16:00:38

遇到这个问题时的一些常用技巧。

  1. 输出生成的SQL并手动测试 - echo $query;
  2. 运行查询后查看 mysql_error() 是否输出任何内容。
  3. 对数据对象使用 var_dump()print_r() 以确保它们符合预期。
  4. 注释掉您的重定向和 exit() 行,以便您可以确定脚本的中断位置。

使用上述确定的任何内容进行修复或评论。

A few common techniques when I encounter this issue.

  1. Output the generated SQL and test it by hand - echo $query;
  2. See if mysql_error() outputs anything after you run your queries.
  3. Use var_dump() and print_r() on your data objects to ensure they are as expected.
  4. Comment out your redirects and exit() lines so you can determine where the script is breaking.

Fix or comment back with anything determined by the above.

画尸师 2024-11-13 16:00:38

您的代码执行查询来查找具有给定用户名的用户,然后检查具有该用户名的行数是否正好为 1。

您看到“无效用户”错误的唯一方法是如果有 0 个具有该用户名的用户或超过 1 个用户使用该用户名。

查看表的内容并检查属于哪一种情况(我推荐 http://sequelpro.com用于在 Mac 上查看数据库内容)。您还可以使用sequel pro 来测试您的查询。

Your code does a query to find a user with the given username, and then checks if the number of rows with that username is exactly 1.

The only way you could see the 'Invalid User' error is if there are 0 users with that username or more than 1 user with that username.

Have a look at the contents of the table and check which of these is the case (I recommend http://sequelpro.com for viewing database contents on a Mac). You can also use sequel pro to test your queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文