警告:mysql_real_escape_string():拒绝用户访问';根'@';本地主机';(使用密码:NO)./public_html/checklogin.php

警告:mysql_real_escape_string():拒绝用户访问';根'@';本地主机';(使用密码:NO)./public_html/checklogin.php,php,html,mysql,Php,Html,Mysql,谢谢你们的出色工作。我刚刚把我的网站上传到远程服务器上,它给我带回了这个错误消息 Warning: mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) in /home/therealimage/public_html/checklogin.php on line 3 Warning: mysql_real_escape_string(): A link to th

谢谢你们的出色工作。我刚刚把我的网站上传到远程服务器上,它给我带回了这个错误消息

Warning: mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) in /home/therealimage/public_html/checklogin.php on line 3

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/therealimage/public_html/checklogin.php on line 3

Warning: mysql_real_escape_string(): Access denied for user 'root'@'localhost' (using password: NO) in /home/therealimage/public_html/checklogin.php on line 4

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/therealimage/public_html/checklogin.php on line 4

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/therealimage/public_html/checklogin.php on line 6
Access denied for user 'root'@'localhost' (using password: NO)
这是我的代码:

    CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

    INSERT INTO `users` (`id`, `username`, `password`) VALUES
(1, 'charles', 'dove'),
(2, 'Editor', 'admin'),
(3, 'Night', 'owl');
我的checklogin.php文件

<?php
    session_start();
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password]);

    mysql_connect("50.28.8.6", "root","") or die(mysql_error()); //Connect to server
    mysql_select_db("therealimage_admin2015") or die("Cannot connect to database"); //Connect to database
    $query = mysql_query("SELECT * from users WHERE username='$username'"); //Query the users table if there are matching rows equal to $username
    $exists = mysql_num_rows($query); //Checks if username exists
    $table_users = "";
    $table_password = "";
    if($exists > 0) //IF there are no returning rows or no existing username
    {
        while($row = mysql_fetch_assoc($query)) //display all rows from query
        {
            $table_users = $row['username']; // the first username row is passed on to $table_users, and so on until the query is finished
            $table_password = $row['password']; // the first password row is passed on to $table_users, and so on until the query is finished
        }
        if(($username == $table_users) && ($password == $table_password)) // checks if there are any matching fields
        {
                if($password == $table_password)
                {
                    $_SESSION['user'] = $username; //set the username in a session. This serves as a global variable
                    header("location: home.php"); // redirects the user to the authenticated home page
                }

        }
        else
        {
            Print '<script>alert("Incorrect Password!");</script>'; //Prompts the user
            Print '<script>window.location.assign("login.php");</script>'; // redirects to login.php
        }

    }
    else
    {
        Print '<script>alert("Incorrect Username!");</script>'; //Prompts the user
        Print '<script>window.location.assign("login.php");</script>'; // redirects to login.php
    }
?>

您可能忘记提供正确的用户名和密码来连接MySQL服务器。在这里
mysql\u connect(“50.28.8.6”、“root”和“”)

或者您没有mysql服务器用户的远程访问权限。只需将localhost更改为%,即可授予根用户访问公共网络的权限。别忘了刷新权限。

问题是您先使用
mysql\u real\u escape\u string()
函数,然后再连接:

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);

mysql_connect("50.28.8.6", "root","") or die(mysql_error()); //Connect to server
解决方案是先连接,然后使用函数
mysql\u real\u escape\u string()


这是因为
mysql\u real\u escape\u string()
需要连接。

您无法连接到数据库。您在
mysql\u connect
中传递的凭据是错误的。除了mysql\u connection参数外,您的代码中还有很多语法错误。感谢兄弟,我最初使用mysql\u connect(“localhost”、“root”、“die”)或mysql\u error();但是还是不行。谢谢你的建议。这一举动让我更加感动了。现在我已经将localhost更改为%,但我得到了以下结果:解析错误:语法错误,意外的“$username”(T_变量),在第8行的/home/doesnews/public_html/checklogin.php中应为“]”。请帮忙?谢谢。是的,我看到你在
$\u POST['password]
中修复了OP缺少的引号。现在OP提出了更多的问题,但没有接受任何问题,tsk tsk。哦,好吧,你能做什么。新年快乐,顺便说一句,;-)干杯编辑:甚至转载了@Fred ii-你好吗,兄弟?祝你和你的家人节日快乐。希望一切都好,弗雷迪!很好,谢谢。一切都很好,希望你也一样。祝你和你的家人节日快乐,干杯!
//Connect to server
mysql_connect("50.28.8.6", "root","") or die(mysql_error()); 
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);