我查看了我的代码,但我仍然无法找到无法将数据输入数据库的原因。
这是我的代码
控制器:
public function user() {
$this->init();
$this->load->model('user');
$user_rows = $this->user->get_user_rows();
if ($user_rows === false) {
$this->json_error($this->user->message);
return;
}
$this->data['user_rows'] = $user_rows;
$this->load->view('admin', $this->data);
}
public function create_user() {
$this->init();
$this->load->view('add_user', $this->data);
}
public function create_user_submit() {
$this->init();
$this->load->model('user');
$this->load->model('user_profile');
$post = array(
'name' => rawurldecode($_POST['name']),
'ic' => rawurldecode($_POST['ic']),
'email' => rawurldecode($_POST['email']),
'tele' => rawurldecode($_POST['telephone']),
'tittle' => rawurldecode($_POST['tittle']),
'username' => rawurldecode($_POST['username']),
'password' => rawurldecode($_POST['password'])
);
$data = $this->user->trans_user_profile($username, $password, $user_create, $pro_id,$pro_name,$pro_ic,$pro_email,$pro_mobile,$pro_tittle,$pro_create);
$new_user = $this->user->create_user($post['username'], $post['password'], $this->login['user_name']);
if($new_user === false){
$this->json_error($this->user->message);
return;
}
$this->json_ok();
}
模型create_user:
public function trans_user_profile($username, $password, $user_create, $pro_id,$pro_name,$pro_ic,$pro_email,$pro_mobile,$pro_tittle,$pro_create) {
$this->load->model('user_profile');
$this->db->trans_start();
$create_user = $this->create_user($username, $password, $user_create, $pro_id);
if ($create_user === false) {
$this->message = $this->db->_error_message();
}
$create_user_profile = $this->user_profile->create_user_profile($pro_name, $pro_ic, $pro_email, $pro_mobile, $pro_tittle, $pro_create);
if ($create_user_profile === false) {
$this->message = $this->db->_error_message();
}
$this->db->trans_complete();
if ($this->db->trans_status() === false){
return false;
}
return true;
}
public function create_user($username, $password, $user_create, $pro_id) {
$this->load->database();
$user = $this->get_user_name_row_case_insensitive($username);
if(sizeof($user) > 0) {
$this->message = $this->error('username_exists');
return false;
}
$seeds = substr(uniqid(), 0,8);
$gpassword = base64_encode(md5($password."_".$seeds, true));
$sql = "insert into user(user_name, user_password, user_seed, user_pro_id, user_created_by, user_created_date)
values(?,?,?,?,?, current_timestap)";
$query = $this->db->query($sql,array(
$username,
$gpassword,
$seeds,
$pro_id,
json_encode(array($gpassword)),
$user_create
));
if($query === false) {
$this->message = $this->db->_error_message();
return false;
}
alert('123');
$member_id = mysql_insert_id();
return true;
}
型号:create_user_profile
public function create_user_profile($pro_name, $pro_ic, $pro_email, $pro_mobile, $pro_tittle, $pro_create,) {
$this->load->database();
$name = $this->get_profile_name_row_case_insensitive($profile_name);
$ic = $this->get_profile_ic_row_case_insensitive($profile_ic);
$email = $this->get_profile_email_row_case_insensitive($profile_email);
if(sizeof($name) > 0) {
$this->message = $this->error('username_exists');
return false;
}
if(sizeof($ic) > 0) {
$this->message = $this->error('IC_exists');
return false;
}
if(sizeof($email) > 0) {
$this->message = $this->error('email_exists');
return false;
}
$sql = "insert into profile(pro_name, pro_ic, pro_email, pro_tel_mobile, pro_job_tittle, pro_created_by, pro_created_by)
values(?,?,?,?,?,?, current_timestap)";
$query = $this->db->query($sql,array(
$pro_name,
$pro_ic,
$pro_email,
$pro_mobile,
$pro_tittle,
$pro_create
));
if($query === false) {
$this->message = $this->db->_error_message();
return false;
}
$pro_id = $this->db->insert_id();
return true;
}
非常感谢你们帮助我。