帐户注册无效?

时间:2014-04-16 21:03:50

标签: php

我有一个简单的帐户创建脚本无效。我知道没有连接错误,因为登录工作正常。此外,我打开错误报告(使其为-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;

}

1 个答案:

答案 0 :(得分:0)

您确定要重新执行插入查询吗? 同样查询sintax是错误的,试试这个:插入用户(用户名,密码)值('admin','1234')。

最后你必须解决安全问题,你的代码会受到sql注入的影响