我在嘗試一些非常基本的東西,但它由於某種原因無法工作!基本上我試圖爲我的網站創建一個新的用戶名和密碼。它僅用於測試。當我提出要求,我得到這樣的:php建立連接失敗
警告:mysql_real_escape_string()[function.mysql實時逃逸字符串]:拒絕訪問用戶santoshs'@ 'localhost' 的(使用密碼:NO) in /home/khali197/public_html/test/enroll.php on line 27
我不知道誰是在這裏顯示的santoshs @ localhost。它從家裏顯示出不同的人。會是什麼呢?
我有下面的代碼,試圖實現我的目標......一切都非常簡單實在:
<?php
class ServerConnection{
function connect(){
$mysqli = new mysqli("localhost", "dsdssd_admin", "sddsdsd",
"khadsdsli197_dsd");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" .
$mysqli->connect_errno . ") " .
$mysqli->connect_error;
}
//echo $mysqli->host_info . "\n";
}
}
?>
的register.php形式:
<form name="register" action="enroll.php" method="post">
Username: <input type="text" name="username" maxlength="30" />
Password: <input type="password" name="pass1" />
Password Again: <input type="password" name="pass2" />
<input type="submit" value="Register" />
</form>
和處理表單,即enroll.php:
<?php
include("ServerConnection.php");
//retrieve our data from POST
$username = $_POST['username'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($pass1 != $pass2)
header('Location: register_form.php');
if(strlen($username) > 30)
header('Location: register_form.php');
$hash = hash('sha256', $pass1);
//creates a 3 character sequence
function createSalt()
{
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
}
$salt = createSalt();
$hash = hash('sha256', $salt . $hash);
$connection = new ServerConnection();
$connection->connect();
$username = mysql_real_escape_string($username);
$query = "INSERT INTO users (username, password, salt)
VALUES ('$username' , '$hash' , '$salt');";
mysql_query($query);
mysql_close();
header('Location: index.php');
?>
這裏任何幫助,將不勝感激!在此先感謝
是你的登錄用戶名'santoshs' mysqli擴展? – 2012-03-05 09:49:26
不是這不是這就是爲什麼我震驚 – 2012-03-13 04:16:25