即时通讯设法编写简单的登录在php + mysql中。每次我点击提交按钮,我得到这个错误无法连接到MySQL:拒绝访问用户'root'@'localhost'(使用密码:是)
无法连接到MySQL:拒绝访问用户“根” @“localhost”的(使用密码:YES)
这是使用即时通讯代码连接到MySQL:
<?php
// Create a connection to the logindb database and to MySQL.
// Set the encoding and the access details as constants:
DEFINE ('DB_USER', 'johny');
DEFINE ('DB_PASSWORD', 'some_pass');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'biblioteczka');
// Make the connection:
$dbcon = @mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME)
OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
$ID = $_POST['user'];
$PASSWORD = $_POST['pass'];
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');
function SignIn(){
session_start();
if(!empty($_POST['user'])){
$query = mysql_query("SELECT * FROM userName where user ='$_POST[user]' and pass = '$_POST[pass]'"
or die(mysql_error));
$row = mysql_fetch_array($query) or die(mysql_error());
if(!empty($row['userName']) AND !empty($row['pass'])){
$_SESSION['userName'] = $row['pass'];
echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";
} else {
echo "SORRY... YOU ENTERD WRONG ID AND PASSWORD... PLEASE RETRY...";
}
}
}
if(isset($_POST['submit']))
{
SignIn();
}
?>
我有2个账户的根和佐尼,他们都特权时,我设置的密码,我可以在我创建数据库。
phpmyadmin的配置:
我不知道哪来的这个点,这就是为什么即时通讯寻求帮助的问题。
对不起,我的英语我不是一个母语
您的错误消息表明您尝试以root身份登录。你的代码说你正在尝试以johny身份登录。你复制了错误的东西。 – Quentin
您在问题**中的问题代码应该是**,而不是在具有链接的外部网站上托管。 – Quentin
**危险**:您正在使用[已删除] [http://php.net/] [已过时**数据库API](http://stackoverflow.com/q/12859942/19068)手册/ en/mysql.php)来自PHP。您应该选择[现代替代品](http://php.net/manual/en/mysqlinfo.api.choosing.php)。你很容易受到[SQL注入攻击](http://bobby-tables.com/)**现代的API会使它更容易[防御](http://stackoverflow.com/questions/60174/最好的方式,以防止SQL注入在PHP)自己从。 – Quentin