注册表不起作用并将数据存储在数据库中(PHP / MYSQL)

时间:2014-03-16 06:35:45

标签: javascript php mysql web content-management-system

我尝试使用PHP / MySQL构建注册页面,第一次当我尝试注册为新用户时,它工作得很好。在某个时间之后,我再次通过注册检查,该页面没有处理数据到数据库。  注册页面信息的以下代码如下 请帮帮我

<?php
    require_once("models/config.php");
    if(isUserLoggedIn()) { header("Location: index.php"); die(); }
?>


<?php
    //Forms posted
    if(!empty($_POST))
    {
        $errors = array();
        $email = trim($_POST["email"]);
        $username = trim($_POST["username"]);
        $password = trim($_POST["password"]);
        $confirm_pass = trim($_POST["passwordc"]);

        //Perform some validation
        //Feel free to edit / change as required

        if(minMaxRange(5,25,$username))
        {
            $errors[] = lang("ACCOUNT_USER_CHAR_LIMIT",array(5,25));
        }
        if(minMaxRange(8,50,$password) && minMaxRange(8,50,$confirm_pass))
        {
            $errors[] = lang("ACCOUNT_PASS_CHAR_LIMIT",array(8,50));
        }
        else if($password != $confirm_pass)
        {
            $errors[] = lang("ACCOUNT_PASS_MISMATCH");
        }
        if(!isValidemail($email))
        {
            $errors[] = lang("ACCOUNT_INVALID_EMAIL");
        }
        //End data validation
        if(count($errors) == 0)
        {   
            //Construct a user object
            $user = new User($username,$password,$email);

            //Checking this flag tells us whether there were any errors such as possible data duplication occured
            if(!$user->status)
            {
                if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($username));
                if($user->email_taken)    $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));       
            }
            else
            {
                //Attempt to add the user to the database, carry out finishing  tasks like emailing the user (if required)
                if(!$user->userPieAddUser())
                {
                    if($user->mail_failure) $errors[] = lang("MAIL_ERROR");
                    if($user->sql_failure)  $errors[] = lang("SQL_ERROR");
                }
            }
    }
    if(count($errors) == 0) 
    {
        if($emailActivation)
        {
            $message = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");
        }
        else {
            $message = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");
        }
    }
}
?>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Registration | <?php echo $websiteName; ?> </title>
    <?php require_once("head_inc.php"); ?>
</head>
<body>
    <div class="modal-ish">
        <div class="modal-header">
            <h2>Sign Up</h2>
        </div>
        <div class="modal-body">
            <div id="success">
                <p><?php echo $message ?></p>
            </div>
            <div id="regbox">
                <form name="newUser" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
                <p>
                    <label>Username:</label>
                    <input type="text" name="username" />
                </p>
                <p>
                    <label>Password:</label>
                    <input type="password" name="password" />
                </p>
                <p>
                    <label>Re-type Password:</label>
                    <input type="password" name="password" />
                </p>
                <p>
                    <label>Email:</label>
                    <input type="text" name="email" />
                </p>
            </div>
        </div>
        <div class="modal-footer">
            <input type="submit" class="btn btn-primary" name="new" id="newfeedform"       value="Register" />
        </div>  
        </form>
    </div>
    <div class="clear"></div>
    <p style="margin-top:30px; text-align:center;">
        <a href="login.php">Login</a> /  <a href="forgot-password.php">Forgot Password?</a> / <a href="<?php echo $websiteUrl;  ?>">Home Page</a>
    </p>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

MySQL代码到底在哪里?您已经完成了对数据的检查,但确实如此。它没有被发送到数据库。它只是经过验证。

答案 1 :(得分:0)

还要正确检查您的连接页面.. 将这类查询添加到您的注册页面..

mysql_query("insert into <your_table>(email,username,password) values('$email',' $username',' $password')");

相关问题