Php 警告:mysql#u real_escape_string()[function.mysql real escape string]:拒绝用户访问';a8221325'@';本地主机';(使用密码:否)

Php 警告:mysql#u real_escape_string()[function.mysql real escape string]:拒绝用户访问';a8221325'@';本地主机';(使用密码:否),php,html,mysql,mysql-real-escape-string,Php,Html,Mysql,Mysql Real Escape String,嗨,由于某种原因,我不知道我一直收到以下错误: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'a8221325'@'localhost' (using password: NO) in /home/a8221325/public_html/add.php on line 11 Warning: mysql_real_escape_string()

嗨,由于某种原因,我不知道我一直收到以下错误:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'a8221325'@'localhost' (using password: NO) in /home/a8221325/public_html/add.php on line 11

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a8221325/public_html/add.php on line 11

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'a8221325'@'localhost' (using password: NO) in /home/a8221325/public_html/add.php on line 12

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a8221325/public_html/add.php on line 12
根据我所做的研究,我觉得问题在于我连接数据库的方式,但我不能完全确定。如果有人能帮我让代码正常工作,那就太棒了! 到目前为止,我的网站由两个页面组成,测试和添加代码如下:

test.html:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="add.php" method="post" name="form1" id="form1">
  <label for="name">Text Field:</label>
  <input type="text" name="name" id="name">
  <label for="password">Text Field:</label>
  <input type="text" name="password" id="password">
  <input type="submit" name="submit" id="submit" value="Submit">
</form>
</body>
</html>

无标题文件
文本字段:
文本字段:
add.php:

<?php
$con=mysqli_connect("mysql1.000webhost.com","a8221325_admin","**************","a8221325_prom");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$escapedName = mysql_real_escape_string($_POST['name']); # use whatever escaping function your db requires this is very important.
$escapedPW = mysql_real_escape_string($_POST['password']);

# generate a random salt to use for this account
$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));

$saltedPW =  $escapedPW . $salt;

$hashedPW = hash('sha256', $saltedPW);

$query = "insert into user (name, password, salt) values ('$escapedName', '$hashedPW', '$salt'); ";
?>

您正在使用mysqli扩展创建数据库连接

然后,您将使用一个名为“mysql”的完全不同的扩展(注意末尾缺少的“i”)进行转义

转义需要现有的mysql连接。如果不存在,将使用默认值隐式创建它。这样做是失败的

但它并没有为您指明正确的方向:您必须使用创建连接的扩展中的转义函数。这是
mysqli\u real\u escape\u string
(注意在“mysql”之后添加了“i”)

一般免责声明:

当使用MySQLI时,使用prepared语句来摆脱转义字符串


不要使用快速散列函数散列密码。包含此实现密码哈希的PHP5.5函数的库:

您正在使用mysqli扩展创建数据库连接

然后,您将使用一个名为“mysql”的完全不同的扩展(注意末尾缺少的“i”)进行转义

转义需要现有的mysql连接。如果不存在,将使用默认值隐式创建它。这样做是失败的

但它并没有为您指明正确的方向:您必须使用创建连接的扩展中的转义函数。这是
mysqli\u real\u escape\u string
(注意在“mysql”之后添加了“i”)

一般免责声明:

当使用MySQLI时,使用prepared语句来摆脱转义字符串


不要使用快速散列函数散列密码。包括这个实现PHP5.5密码散列函数的库:

mysql\u real\u escape\u string
是扩展的函数,
mysqli\u connect
是扩展的函数。您不应该在散列用户密码之前对其进行清理,但在将散列插入数据库之前,对抛出的错误消息有什么不清楚的地方?@PeeHaa:这实际上有点棘手,尤其是对于新手
mysql\u real\u escape\u string
mysql
扩展的函数,
mysqli\u connect
mysqli
扩展的一个功能。在散列用户密码之前,不应该对其进行清理,但在将散列插入数据库之前,抛出的错误消息有什么不清楚的地方?@PeeHaa:这实际上有点棘手,尤其是对于新手来说,如果您提到prepared语句就好了如果您提到prepared语句就好了