帮助我卡住
这就是我想要实现的目标:
当用户点击按钮时,它将:
如果用户ID不存在,请执行以下操作:
我坚持第3点,第2点和第2点3(不能插入两个表)
控制器
$dbh=new PDO("mysql:charset=utf8mb4;host=$hostname;dbname=dbtest",$username ,$password);
模型
function beforeSave() {
$this->load->model('admin/user_detail_model', 'user_detail_model');
$this->load->model('admin/es_user_model', 'es_user_model');
$noPengenalan = $this->input->post('noPengenalan');
$userIdAvailable = $this->individu_model->check_if_userid_exists($noPengenalan);
if (count($userIdAvailable) > 0) {
echo "exist";
}else{
$tamatPassport = $this->input->post('tamatPassport');
$user_detail = $this->user_detail_model->save(array(
'USER_SEX' => $this->input->post('jantina'),
'USER_NATIONALITY' => $this->input->post('warganegara'),
'USER_ID' => $this->input->post('noPengenalan'),
'USER_NEGARA' => $this->input->post('negara'),
'USER_PASSPORT_EXPIRED' => "to_date('$tamatPassport','dd/mm/yyyy')",false,
'USER_ADDRESS' => $this->input->post('alamat'),
'USER_ADDRESS2' => $this->input->post('alamat2'),
'USER_ADDRESS3' => $this->input->post('alamat3'),
'USER_CITY' => $this->input->post('bandar'),
'USER_NEGERI' => $this->input->post('negeri'),
'USER_POSTCODE' => $this->input->post('poskod'),
'USER_NOTEL' => $this->input->post('noTel'),
'USER_NOTEL_HP' => $this->input->post('noHp'),
'USER_NOTEL_OFFICE' => $this->input->post('noPejabat'),
'USER_EMAIL' => $this->input->post('email')
));
$es_user = $this->es_user_model->save(array(
'USER_ID' => $this->input->post('USER_ID'),
'USER_NAME' => $this->input->post('USER_NAME'),
'EU_ICTYPE' => $this->input->post('EU_ICTYPE')
));
// send email
$this->load->library('email','email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx@gmail.com', // change it to yours
'smtp_pass' => 'xxxx', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$data['noPengenalan'] = $this->input->post('noPengenalan');
$data['namaPenuh'] = $this->input->post('namaPenuh');
$today = date('m/d/Y');
$new = date('m/d/Y', strtotime("+3 months", strtotime($today)));
$data['date_register'] = $today;
$data['date_expired'] = $new;
$message = $this->load->view('profile/individu/email_activation', $data, TRUE);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx@gmail.com'); // change it to yours
$this->email->to('yyyy@gmail.com');// change it to yours
$this->email->subject('Permohonan ID Individu - ' . $noPengenalan);
$this->email->message($message);
$this->email->send();
echo "continue";
}
}
AJAX
public function save($data)
{
$this->db->set('USER_SEX', $data['USER_SEX']);
$this->db->set('USER_NATIONALITY', $data['USER_NATIONALITY']);
$this->db->set('USER_ID', $data['USER_ID']);
$this->db->set('USER_NEGARA', $data['USER_NEGARA']);
$this->db->set('USER_PASSPORT_EXPIRED',$data['USER_PASSPORT_EXPIRED']);
$this->db->set('USER_ADDRESS', $data['USER_ADDRESS']);
$this->db->set('USER_ADDRESS2', $data['USER_ADDRESS2']);
$this->db->set('USER_ADDRESS3', $data['USER_ADDRESS3']);
$this->db->set('USER_CITY', $data['USER_CITY']);
$this->db->set('USER_NEGERI', $data['USER_NEGERI']);
$this->db->set('USER_POSTCODE', $data['USER_POSTCODE']);
$this->db->set('USER_NOTEL', $data['USER_NOTEL']);
$this->db->set('USER_NOTEL_HP', $data['USER_NOTEL_HP']);
$this->db->set('USER_NOTEL_OFFICE', $data['USER_NOTEL_OFFICE']);
$this->db->set('USER_EMAIL', $data['USER_EMAIL']);
$this->db->insert('USER_DETAILS');
}