2014-03-19 50 views
0

我正在开发一个用户注册和登录的网站,完成页面配置后,我试图注册它完美的工作,并在第二天晚些时候我试图注册,但页面未加载,之后在填写资料,如果我点击提交,重新加载没有效果相同的注册页面,如何解决这个问题注册页面不处理数据到数据库

SQL Query Processing code: (class.newuser.php) 

enter code here 




     class User 
     { 
     public $user_active = 0; 
     private $clean_email; 
     public $status = false; 
     private $clean_password; 
     private $clean_username; 
     private $unclean_username; 
     public $sql_failure = false; 
     public $mail_failure = false; 
     public $email_taken = false; 
     public $username_taken = false; 
     public $activation_token = 0; 

     function __construct($user,$pass,$email) 
     { 
     //Used for display only 
     $this->unclean_username = $user; 

    //Sanitize 
    $this->clean_email = sanitize($email); 
    $this->clean_password = trim($pass); 
    $this->clean_username = sanitize($user); 

    if(usernameExists($this->clean_username)) 
    { 
    $this->username_taken = true; 
    } 
    else if(emailExists($this->clean_email)) 
    { 
    $this->email_taken = true; 
    } 
    else 
    { 
    //No problems have been found. 
    $this->status = true; 
    } 
    } 

    public function userPieAddUser() 
    { 
    global $db,$emailActivation,$websiteUrl,$db_table_prefix; 

    //Prevent this function being called if there were construction errors 
    if($this->status) 
    { 
    //Construct a secure hash for the plain text password 
    $secure_pass = generateHash($this->clean_password); 

    //Construct a unique activation token 
    $this->activation_token = generateactivationtoken(); 

    //Do we need to send out an activation email? 
    if($emailActivation) 
    { 
     //User must activate their account first 
     $this->user_active = 0; 

     $mail = new userPieMail(); 

     //Build the activation message 
     $activation_message = lang("ACTIVATION_MESSAGE",array("{$websiteUrl}/",$this->activation_token)); 

     //Define more if you want to build larger structures 
     $hooks = array(
      "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"), 
      "subjectStrs" => array($activation_message,$this->activation_token,$this->unclean_username) 
     ); 

     /* Build the template - Optional, you can just use the sendMail function 
     Instead to pass a message. */ 
     if(!$mail->newTemplateMsg("new-registration.txt",$hooks)) 
     { 
      $this->mail_failure = true; 
     } 
     else 
     { 
      //Send the mail. Specify users email here and subject. 
      //SendMail can have a third parementer for message if you do not wish to build a template. 

      if(!$mail->sendMail($this->clean_email,"New User")) 
      { 
       $this->mail_failure = true; 
      } 
     } 
    } 
    else 
    { 
     //Instant account activation 
     $this->user_active = 1; 
    } 


    if(!$this->mail_failure) 
    { 
      //Insert the user into the database providing no errors have been found. 
      $sql = "INSERT INTO `".$db_table_prefix."users` (
        `username`, 
        `username_clean`, 
        `password`, 
        `email`, 
        `activationtoken`, 
        `last_activation_request`, 
        `LostpasswordRequest`, 
        `active`, 
        `group_id`, 
        `sign_up_date`, 
        `last_sign_in` 
        ) 
        VALUES (
        '".$db->sql_escape($this->unclean_username)."', 
        '".$db->sql_escape($this->clean_username)."', 
        '".$secure_pass."', 
        '".$db->sql_escape($this->clean_email)."', 
        '".$this->activation_token."', 
        '".time()."', 
        '0', 
        '".$this->user_active."', 
        '1', 
        '".time()."', 
        '0' 
        )"; 

     return $db->sql_query($sql); 
    } 
} 
} 
} 
?> 

HTML register.php

enter code here 





    <?php 
require_once("models/config.php"); 


//Prevent the user visiting the logged in page if he/she is already logged in 
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 
      { 
       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"); 
      } 
    } 
    } 
     ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <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="passwordc" /> 
      </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> 
+0

你自己做过任何基本的调试吗?在处理逻辑中加入一些回声以查看它是否在哪里出现?检查生成的$ sql的错误? –

回答

0

一切因div标签它:

在窗体标签内关闭了2个分区,但它们在窗体标签外部打开。

因此试着把整个表格放在一个div(regbox)中包括提交。

并确保在表单标签外部打开的表单标签内没有关闭div。