注册系统

时间:2013-06-30 12:34:40

标签: php mysql login

当我想在我的网站上注册我正在创建

时,我收到此错误
Notice: Undefined index: username in C:\xampp\htdocs\Code\login.php on line 35

Notice: Undefined index: password in C:\xampp\htdocs\Code\login.php on line 40
password doesn't match.

就是这样:

<?php
    if(isset($_POST['register'])){
        if(empty($_POST['rusername']) or empty($_POST['rpassword']) or empty($_POST['crpassword'])){
        echo "Fields cannot be empty";
        }else{
            $do = mysql_query("SELECT * From users WHERE username='".mysql_real_escape_string($_POST['username'])."'");
            if(mysql_num_rows($do) == 1){
            echo "Users busy.";
            }else{
                $rusername = mysql_real_escape_string($_POST['rusername']);
                $password = mysql_real_escape_string(sha1($_POST['password']));
                $rpassword = $_POST['rpassword'];
                if($password == $rpassword){
                    mysql_query("INSET INTO users (username, password) VALUES ('$rusername','$rpassword')");
                    echo "Account created.";
                }else{
                echo "password doesn't match.";
                }
            }
        }
    }
    ?>

希望有人可以帮助我:)。

这是HTML CODE:

<form method="post"> 

&nbsp;Anv&#228;ndarnamn:<input type="text" placeholder="Ditt användarnamn" class="mywidth1" name="rusername"><br /> 
    &nbsp;L&#246;senord:<input type="password" placeholder="Ditt lösenord" class="mywidth2" name="rpassword"><br />
&nbsp;Verifiera l&#246;senord: <input type="password" placeholder="Skriv lösenordet igen" class="mywidth" name="crpassword"><br />
 <input type="submit" class="regbutton" value="" name="register">
</form>

寄存器

1 个答案:

答案 0 :(得分:1)

您的代码指的是$_POST['username'],在此行中应该引用$_POST['rusername']

$do = mysql_query("SELECT * From users WHERE username='".mysql_real_escape_string($_POST['username'])."'");

这些行

$password = mysql_real_escape_string(sha1($_POST['password']));
$rpassword = $_POST['rpassword'];
if($password == $rpassword){
.
.
}

$_POST['password']的散列转义版本与未展开的非转义版$_POST['rpassword']进行比较 - 我看不出它们将如何相等。

在您的HTML中,您使用了与用于电子邮件地址字段的用户名字段相同的名称。 PHP将使用电子邮件地址作为用户名。

您需要查看此代码并修复这些明显的错误。如果这还不够清楚,请考虑雇用某人为您完成工作。