无法理解错误:用户“Pratik”@“localhost”的访问被拒绝(使用密码:NO)进入php

发布于 2024-09-16 06:09:44 字数 351 浏览 1 评论 0原文

首先我只是澄清问题。 我正在测试我网站的登录页面。 所以我有两个用于测试的登录文件,它们都包含相同的代码,但都保存在名为“signin.php”的不同位置。分别是“login.php”

问题是当我尝试从位于根文件夹(www)的“signin.php”登录时出现错误:用户“Pratik”@“localhost”的访问被拒绝(使用密码:NO)。在此我使用会话。

当我尝试从位于“c:\Temp\”文件夹中的“login.php”登录时,成功运行。 &根据我的代码创建用户名会话。

现在我再次尝试“signin.php”登录,然后这次登录成功。 但当会话过期时。 &我尝试再次从“signin.php”登录,它再次显示上述错误。

firstly i just clearify the problem.
i am testing the page of login of my website.
so i have two login files for testing that both contain same code but both are save in different place named "signin.php" & "login.php" resp.

the problem is when i try to login from "signin.php" which located in root folder(www) gives an error:Access denied for user 'Pratik'@'localhost' (using password: NO).in this i use session.

when i try to login from "login.php" which is located in "c:\Temp\" folder runs sucessfully. & create session of username as per my code.

now i try "signin.php" again for login, then this time it login sucessfully.
but when session expire. & i try to login from "signin.php" again it show above error again.

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

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

发布评论

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

评论(3

醉生梦死 2024-09-23 06:09:44

它表示您正在使用用户名:Pratik 和空密码访问数据库。

如果没有任何密码,它将无法连接。

It's saying that you are accessing the database with username: Pratik and an empty password.

It won't connect without any password.

西瑶 2024-09-23 06:09:44

检查您的 mysql_connect() (或 mysqli_connect())语句。如果您在多个地方使用它,显然其中一个或多个地方会有所不同,很可能是由于变量不在正确的范围内。例如:

$user = 'Pratik'
$host = 'localhost';
$password = '...';

function db_conn() {
    global $user, $host;
    $con = mysql_connect($host, $user, $password);
}

这将失败,因为您没有在函数内声明全局的 $password,因此您将得到一个空白密码和“使用密码:否”的错误。

Check your mysql_connect() (or mysqli_connect()) statements. If you're using that in multiple places, obviously one or more of them differ somehow, most likely by a variable not being in the proper scope. For instance:

$user = 'Pratik'
$host = 'localhost';
$password = '...';

function db_conn() {
    global $user, $host;
    $con = mysql_connect($host, $user, $password);
}

This will fail as you have no declared $password to be global within the function, so you'll get a blank password and "Using password: NO" for an error.

羅雙樹 2024-09-23 06:09:44

这是因为您的文档根目录设置为
c:/Temp/ 不是默认的 c:/xampp/htdocs(如果是 xampp)或 c:/xampp/www/(对于 WAMP)。

要更改它,请转到 c:/xampp/apache/httpd.conf 或安装 apache 的位置。搜索文档根目录并将其设置为所需的路径。

希望这有帮助..:)

This is because your document root is set to
c:/Temp/ not the default c:/xampp/htdocs(in case of xampp) or c:/xampp/www/(in case of WAMP).

To change it go to c:/xampp/apache/httpd.conf or where ever your apache is installed. Search for the Document root and set to to desired path.

Hope this was helpful.. :)

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