0
我有一個不起作用的簡單賬戶創建腳本。我知道沒有連接錯誤,因爲登錄工作正常。另外,我打開錯誤報告(使它-1),但它沒有顯示錯誤 這是我的代碼片段,由於 HTML帳戶註冊不起作用?
<form method="post">
<input type="text" name="newUsername" placeholder="Username"/>
<input type="password" name="newPassword" placeholder="Password"/>
<input type="submit" name="signUp" value="Sign Up!"/>
</form>
然後PHP:
if($_POST['signUp']) {
$username = $_POST['newUsername'];
$pass = $_POST['newPassword'];
$signedUp = SignUp($Username,$pass);
echo $signUpCode[$signedUp]; // See the SignUp function in prefunc.php
} elseif($_POST['LogIn']) {
$username = $_POST['Username'];
$password = $_POST['Password'];
$loggedIn = LogIn($username,$password);
echo $logInCode[$loggedIn];
}
$signUpCode = Array(
"-3"=>"Logged in already - can't sign up!",
"-2"=>"Username already exists!",
"-1"=>"Failed to sign up - please try again!",
"1"=>"Signed up, and logged in successfully!"
);
function SignUp($Username,$Password) {
$Username = preg_replace("/[^a-zA-Z0-9]/","",$Username);
$u = mysql_query("SELECT * FROM Users WHERE LOWER(Username)=LOWER('$Username')");
if(getCurrentId()){
return -3;
}
if(!mysql_num_rows($u)) {
mysql_query("INSERT INTO Users SET Username='$Username',Password=''$Password") or die(mysql_error());
$u = mysql_query("SELECT * FROM Users WHERE LOWER(Username)=LOWER('$Username')");
if(mysql_num_rows($u)) {
LogIn($Username,$Password);
return 1;
} else {
return -1;
}
}
return -2;
}
錯字 - 的mysql_query(「INSERT INTO用戶設置的用戶名=‘$用戶名’,密碼='$密碼」),它應該是的mysql_query (「INSERT INTO Users SET」用戶名='$用戶名',密碼='$密碼'「 –
Quotes out of whack'SET用戶名='用戶名',密碼=''$密碼」)'---'SET用戶名= '$用戶名',密碼='$密碼'「)'錯字肯定(*右?*)。另外,除非只是個人項目,否則不要使用純文本密碼。更何況'mysql_ *' –
它現在有效,謝謝,問題是它插入一個空白的用戶名 – Sam