未知栏' a9162e80e079a0051c8b7f88195a94da'在'字段列表' (加密密码)

时间:2014-11-06 11:32:21

标签: php mysql passwords registration password-encryption

我已经检查并尝试更改我的代码,但仍然是同样的错误,我试图解决这个问题大约2天,每天大约2-3个小时的思考和改变。

我对此很新,无法找到错误所在的行。 我在这里研究过这个问题,但仍无法找到答案。试图添加''仍然没有,我的mysql表也存在,我确定它。

需要一些帮助。

if(isset($_POST["register"])){
    $username = protect($_POST['username']);
    $password = protect($_POST['password']);
    $email = protect($_POST['email']);

    if(strlen($username) > 20){
        echo "Username must be less than 20 characters!";
    }elseif(strlen($email) > 100){
        echo "E-mail must be less than 100 characters!";
    }elseif(strlen($username) < 4){
        echo "Username must be more than 4 characters!";
    }elseif(strlen($password) < 4){
        echo "Password must be more than 4 characters!";
    }else{
        $register1 = @mysql_query("SELECT id FROM user WHERE username = '$username' ") or die(@mysql_error());
        $register2 = @mysql_query("SELECT id FROM user WHERE email = '$email' ") or die(@mysql_error());
        if(@mysql_num_rows($register1) > 0){
            echo "That username is already in use!";
        }elseif(mysql_num_rows($register2) > 0){
            echo "That e-mail address is already in use!";
        }else{
            $ins1 = @mysql_query("INSERT INTO stats (gold, attack, defense, food) VALUES (100,10,10,100)") or die(mysql_error());
            $ins2 = @mysql_query("INSERT INTO unit (worker, farmer, warrior, defender, archer, longbowmen, phalanxmen, knight, cavalary) VALUES (5, 5, 0, 0, 0, 0, 0, 0, 0)") or die(mysql_error());
            $ins3 = @mysql_query("INSERT INTO user (username, password, email) VALUES('$_POST[$username]', ".md5('$_POST[$password]')." ,'$_POST[$email]')") or die(mysql_error());
            $ins4 = @mysql_query("INSERT INTO weapon(sword, shield, bow, longbow, towershield, longsword, pike, horse) VALUES (0, 0, 0, 0, 0, 0, 0, 0)") or die(mysql_error());
            $ins5 = @mysql_query("INSERT INTO ranking (attack, defense, overall) VALUES (0,0,0)");
                echo("Congratulations, You have registered!");

        }
    }
}

2 个答案:

答案 0 :(得分:1)

使用''来包围您的密码值,否则mysql将文本解释为列的名称而不是值:

    $ins3 = @mysql_query("INSERT INTO user (username, password, email) VALUES('$_POST[$username]', '".md5('$_POST[$password]')."' ,'$_POST[$email]')") or die(mysql_error());

答案 1 :(得分:0)

".md5('$_POST[$password]')."替换为'".md5('$_POST[$password]')."'(添加引号)