2012-01-24 1 views
0

何らかの理由で、フォームを送信したときに返されたものが「ユーザーの作成に問題がありました。もう一度やり直してください!それでもまだ新しいデータベースエントリが作成されていますが、その理由はわかりません。私は自分のフォームでテストを行っていますが、私が提出しているデータは私に成功メッセージを与えるべきです。何か案は?希望のエラー/成功メッセージを返さない

編集:私は今2日間試しましたが、まだこれを理解できないようです。

コントローラー:

function register_submit() 
{ 
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower'); 
    $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email'); 
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric'); 
    $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]|min_length[6]|max_length[12]|alpha_numeric'); 
    $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|xss_clean|alpha'); 
    $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|xss_clean|alpha');  

    if (!$this->form_validation->run()) 
    { 
     echo json_encode(array('error' => 'yes', 'message' => 'There was a problem submitting the form! Please refresh the window and try again!'));  
    } 
    else 
    {       
     $user_data = $this->kow_auth->create_user($this->input->post('username'), $this->input->post('email'), $this->input->post('password'), $this->input->post('first_name'), $this->input->post('last_name')); 
     if ($user_data == FALSE)  
     { 
      echo json_encode(array('error' => 'yes', 'message' => 'There was a problem creating the user! Please try again!')); 
     }  
     else 
     { 
      $data['activation_period'] = 48; 
      $this->kow_auth->send_email('activate', $data['email'], $data); 
      unset($data['password']); 
      echo json_encode(array('sucess' => 'yes', 'message' => 'You have successfully registered. Check your email address to activate your account!')); 
     } 
    } 
} 

図書館:

/** 
* Create new user on the site and return some data about it: 
* user_id, username, password, email, new_email_key (if any). 
* 
* @param string 
* @param string 
* @param string 
* @param string 
* @param string 
* @return array 
*/ 
function create_user($username, $email, $password, $first_name, $last_name) 
{ 
    if ((strlen($username) > 0) AND !$this->ci->users->is_username_available($username)) 
    { 
     return FALSE; 
    } 
    elseif (!$this->ci->users->is_email_available($email)) 
    { 
     return FALSE; 
    } 
    else 
    { 
     $genPassHash = $this->ci->genfunc->GenPassHash($password); 

     $max_user_id = $this->ci->users->get_max_users_id(); 

     $data = array(
      'username'  => $username, 
      'password'  => $genPassHash[0], 
      'password2'  => $genPassHash[1], 
      'email'   => $email, 
      'first_name' => $first_name, 
      'last_name'  => $first_name, 
      'new_email_key' => md5(rand().microtime()), 
      'user_id'  => $max_user_id, 
      'ip_address' => $this->ci->input->ip_address() 
     ); 

     if (($result = $this->ci->users->create_user($data)) == FALSE) 
     { 
      $data['user_id'] = $res['user_id']; 
      $data['password'] = $password; 
      unset($data['last_ip']); 
      return $data; 
     } 
    } 
    return FALSE; 
} 

ユーザーモデル:

/** 
* Create new user record 
* 
* @param array 
* @return bool 
*/ 
function create_user($data) 
{ 
    $data['date_created'] = date('Y-m-d H:i:s'); 

    $this->db->set('username', $data['username']); 
    $this->db->set('password', $data['password']); 
    $this->db->set('password2', $data['password2']); 
    $this->db->set('email', $data['email']); 
    $this->db->set('first_name', $data['first_name']); 
    $this->db->set('last_name', $data['last_name']); 
    $this->db->set('ip_address', $data['ip_address']); 
    $this->db->set('date_created', $data['date_created']); 

    $query = $this->db->insert('users'); 

    if ($query) 
    { 
     return TRUE; 
    } 
    else 
    { 
     return FALSE; 
    } 
} 
+0

まあ、それは== FALSEではありません。だから、そこに何があなたを助けてくれるのかを見るために、user_dataをエコーするかもしれません。 –

+0

データが正常に正しく入力されているが、エラーを報告している場合は、戻り値の作成と評価を確認することをお勧めします。 – horatio

+0

直後にエコーとprint_rを実行しましたが、何もありません。それは役に立たない。 –

答えて

0

私はあなたが持っているかもしれないと思いますこれらの挿入と$クエリのいくつかの時点でのいくつかのSQLエラーはFALSEです。この部分的な挿入を避けるためにトランザクションについて読むべきです。基本的には、ロジック内の挿入が失敗してトランザクションに関する情報が読み込まれた場合、そのインサートをperfprmする必要はありません。あなたはあなたが使用しているDBプラットフォームを指定していませんでしたので、私は確かなリンクを与えることはできません...ここにあなたのmysqlを使用してリンクしている場合:http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html

関連する問題