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;
}
}
那麼無論是在USER_DATA它沒有= = FALSE。所以可能是回聲user_data看看裏面有什麼會幫助你。 –
沒錯,如果數據輸入正確且完全如預期,但是您報告錯誤,最好的辦法就是檢查您的創建並評估返回值 – horatio
我在它後面做了一個echo和print_r,但沒有任何內容。所以這沒有幫助。 –