两个不同的表和相同的列名,同时在两个表中插入电子邮件ID检查,如果表中存在相同的电子邮件ID,则不再插入表中。
型号代码
function form_insert($data, $data1) {
if ($data1['categoryvalues'] == 'Seller') {
$this->db->insert('supplier_registration', $data);
return ($this->db->affected_rows() != 1) ? false : true;
} else {
$this->db->insert('customer_registration', $data);
return ($this->db->affected_rows() != 1) ? false : true;
}
}
控制器代码
function register() {
$this->form_validation->set_rules('email', 'Email', 'callback_rolekey_exists');
$this->form_validation->set_rules('fname', 'First Name', 'required|min_length[3]|max_length[30]');
$this->form_validation->set_rules('lname', 'Last Name', 'required|min_length[3]|max_length[30]');
$this->form_validation->set_rules('email', 'Email ID', 'required|valid_email|is_unique[supplier_registration.email]');
$this->form_validation->set_rules('mobileno', 'Mobile No', 'required|regex_match[/^[0-9]{10}$/]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[15]|min_length[8]|matches[ConfirmPassword]');
$this->form_validation->set_rules('ConfirmPassword', 'Confirm Password', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$data['ListMenuLevel1'] = $this->Categories_model->listsector1();
$data['groups1'] = $this->productdisplay_model->fetchingdata();
$data['flag2'] = "yes";
//$data['message']="invalid username or password";
$this->load->view('home', $data);
//$data['flag'] = 'yes';
//$this->load->view('login', $data);
} else {
$data = array(
'first_name' => $this->input->post('fname'),
'last_name' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'mobile_no' => $this->input->post('mobileno'),
'password' => $this->input->post('password')
);
$data1['categoryvalues'] = $this->input->post('optradio');
if ($this->Register_model->form_insert($data, $data1)) {
$data['ListMenuLevel1'] = $this->Categories_model->listsector1();
$data['groups1'] = $this->productdisplay_model->fetchingdata();
$data['message'] = 'Data Inserted Successfully';
$this->load->view('home', $data);
}
}
}
答案 0 :(得分:1)
据我所知,您没有理由不能多次使用is_unique检查。
$this->form_validation->set_rules('email', 'Email ID', 'required|valid_email|is_unique[supplier_registration.email]|is_unique[customer_registration.email]');