谢谢你们,你们所做的出色工作。我刚刚将我的网站上传到远程服务器上,它给我带回了这条错误消息。
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
}
?>
答案 0 :(得分:1)
问题是你首先使用android.view.InflateException: Binary XML file line #16: Error inflating class android.support.v7.widget.RecyclerView
函数然后连接:
mysql_real_escape_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_real_escape_string()
这是因为//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']);
需要连接。
答案 1 :(得分:0)
您可能忘记提供正确的用户名和密码以连接到MySQL服务器。这里mysql_connect("50.28.8.6", "root","")
答案 2 :(得分:0)
或者您对mysql服务器用户没有远程访问权限。只需将localhost更改为%即可授予对公共网络的root访问权限。不要忘记刷新权限。