用户注册-错误的逻辑

User Registration - Incorrect Logic

本文关键字:错误 用户注册      更新时间:2023-09-26

我的代码有多个问题。我写了一个用户注册表单与验证,但我需要帮助,我会写它保存在数据库中,如果我错过了什么。到目前为止,它不起作用。当我点击register时,它只是刷新页面。

我很感激你的帮助,谢谢。

<!DOCTYPE html>
<html lang="en">
<head>
<SCRIPT language="JavaScript"> 
                function validateRegistrationForm(){
            if(!validateEmailField()) // Invalid email format
            return false;
            if(!validatePasswordField()) // Invalid password length
            return false;
            if(validateUserNameField()) // invalide characters in email
        return false;
}
            function validateEmailField(){
            var x=document.getElementById("email").value;
            var atpos=x.indexOf("@");
            var dotpos=x.lastIndexOf(".");
            if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
            errorPopup("Not a valid e-mail address");
            return false;
}
    if(email==x) //If the old email is equal to the current then perform no check for uniqueness. On the server side the email portion will be ignored.
        return true;
    return isEmailUnique(); // return true if the email is unique
}
</script>

</head>
<body class="nobg loginPage">
    <header>
    </header>
    <div id="content">
        <div class="ic"></div>
        <div class="inner">
            <div class="container_12">
                <div class="wrapper">
                    <div class="grid_12">
                    </div>
                </div>
                <div class="wrapper">
                    <div class="grid_12">
                        <h2 class="h-pad1">Open an Account with Us</h2>
                        <form action="" id="validate" class="form" method="POST">
            <fieldset>
                <div class="formRow">
                    <label for="login">Username:</label>
                    <div class="loginInput"><input type="text" name="username" class="validate[required]" id="username" maxlength="15"/></div>
                    <div class="clear"></div>
                </div>
                <div class="formRow">
                    <label for="pass">Password:</label>
                    <div class="loginInput"><input type="password" name="password" class="validate[required]" id="pass" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formRow">
                    <label for="pass">Repeat Password:</label>
                    <div class="loginInput"><input type="password" name="rpassword" class="validate[required]" id="rpass" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formRow">
                    <label for="pass">Email:</label>
                    <div class="loginInput"><input type="text" name="email" class="validate[required]" id="email" /></div>
                    <div class="clear"></div>
                </div>
                <div class="formRow5">
                <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6Lfz39kSAAAAABY7fpEs0x1ZzvcFSP-gClbe8XYb"></script>
                <noscript>
                <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Lfz39kSAAAAABY7fpEs0x1ZzvcFSP-gClbe8XYb" height="300" width="500" frameborder="0"></iframe><br/>
                <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
                <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
                </noscript> </div>
                <div class="loginControl">
                    <input type="submit" value="Register" class="dblueB logMeIn" name="registerBtn"/>
                    <div class="clear"></div>
                </div>
            </fieldset>
        </form>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>          
        </div>
    </div>
    <footer>
        </div>
    </footer>
</body>
</html>

据我所知,您没有任何东西将表单的提交链接到您编写的验证代码。当您提交表单时,是否调用了validateRegistrationForm()函数?

至于你的函数-你会想要返回true,如果表单元素是有效的,和false,如果他们不是。返回false将取消提交表单

在大多数情况下,您不能使用JavaScript编写数据库,因为JS是客户端代码,而数据库往往位于服务器上。在这种情况下,你需要使用服务器端语言(如。net、PHP、Java等)。如果你能说出你想要写的数据库和你正在使用的服务器语言(如果你已经在使用任何),你可能能够得到一个更详细的答案。

在你点击注册按钮之前,有一个javascript错误…

第14行第1列:"Uncaught SyntaxError: Unexpected token。"