我正在使用Codeginator,我有3个表(将来会根据要求增加),表名是"tbl_customer", "tbl_customer_billing","tbl_customer_shipping"
。每个表都连接有主键和外键。
现在我要在每个表中插入数据,所以我尝试了下面的代码。
我的问题是:
1)我应该为每个数组使用$this->security->xss_clean()
吗?或任何其他仅使用单个xss_clean
的想法?
2)在多个表中插入数据的最佳,最快的方法是什么?
我尝试了以下代码。可以吗?还是应该使用其他方式? 我尝试使用下面的代码,但是丢失数据有很多更改。还有其他想法吗?
控制器:
public function add_newcustomer(){
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('c_firstname', 'Firstname', 'trim|required|min_length[3]|max_length[25]');
$this->form_validation->set_rules('c_lastname', 'Lastname', 'trim|required|min_length[3]|max_length[25]');
$this->form_validation->set_rules('c_email', 'Email', 'required');
$this->form_validation->set_rules('c_mobileno', 'Mobile no', 'trim|required|regex_match[/^[0-9]{10}$/]');
$this->form_validation->set_rules('c_billing_address', 'Billing Address', 'required|min_length[10]|max_length[100]');
$this->form_validation->set_rules('c_b_country', 'Country', 'required');
$this->form_validation->set_rules('c_b_state', 'State', 'required');
$this->form_validation->set_rules('c_b_city', 'City', 'required');
$this->form_validation->set_rules('c_b_zipcode', 'Zip code', 'required');
$this->form_validation->set_rules('c_shopping_address', 'Shopping Address', 'required|min_length[10]|max_length[100]');
$this->form_validation->set_rules('c_s_country', 'Country', 'required');
$this->form_validation->set_rules('c_s_state', 'State', 'required');
$this->form_validation->set_rules('c_s_city', 'City', 'required');
$this->form_validation->set_rules('c_s_zipcode', 'Zip code', 'required');
if ($this->form_validation->run() == FALSE)
{
$data['get_country']=$this->Customer_model->get_country();// all country name
$this->load->view('create_order',$data);
}
else
{
$cust_personal = array(
'c_firstname'=>$this->input->post('c_firstname'),
'c_middlename'=>$this->input->post('c_middlename'),
'c_lastname'=>$this->input->post('c_lastname'),
'c_email_id'=>$this->input->post('c_email'),
'c_mobileno'=>$this->input->post('c_mobileno'),
'c_alternetno'=>$this->input->post('c_alternetno'),
'c_created_by_emp'=>$this->session->userdata['login_session']['id'],
'c_date_of_added'=>$this->current_date
);
$this->db->insert('tbl_customer',$cust_personal);
$last_cust_id= $this->db->insert_id();
$cust_billing = array(
'c_b_address'=>$this->input->post('c_billing_address'),
'c_b_country'=>$this->input->post('c_b_country'),
'c_b_state'=>$this->input->post('c_b_state'),
'c_b_city'=>$this->input->post('c_b_city'),
'c_b_zipcode'=>$this->input->post('c_b_zipcode'),
'cust_id'=>$last_cust_id,
'c_date_of_added'=>$this->current_date
);
$this->db->insert('tbl_customer_billing',$cust_billing);
$last_billing_id= $this->db->insert_id();
$cust_shipping = array(
'c_s_address '=>$this->input->post('c_shopping_address'),
'c_s_country'=>$this->input->post('c_s_country'),
'c_s_state'=>$this->input->post('c_s_state'),
'c_s_city'=>$this->input->post('c_s_city'),
'c_s_zipcode'=>$this->input->post('c_s_zipcode'),
'c_s_receiver_no'=>$this->input->post('c_receiver_no'),
'cust_id'=>$last_cust_id,
'c_billing_id'=>$last_billing_id,
'c_date_of_added'=>$this->current_date
);
$this->db->insert('tbl_customer_shipping',$cust_shipping);
redirect("Customer_control/index");
}
}