嗨,由於某種原因我不知道我繼續收到以下錯誤:警告:mysql_real_escape_string()[function.mysql-real-escape-string]:訪問拒絕用戶'a8221325'@'localhost'(使用密碼:否)
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'); ";
?>
謝謝!
'mysql_real_escape_string'是'mysql'擴展的函數,''mysqli_connect'是'mysqli'擴展的函數。而且你不應該清理用戶的密碼**在使用前,你需要對它進行哈希處理,但在將哈希插入數據庫之前 – zerkms
對於拋出的錯誤消息,有哪些不清楚的地方? – PeeHaa
@PeeHaa:它實際上有點棘手,尤其是對於一個新手 – zerkms