jquery - having an issue when edited a row again it is inserting a new row in php codeigniter -
jquery - having an issue when edited a row again it is inserting a new row in php codeigniter -
i have issue edit , update row having file upload field. problem when inserting row if there file uploaded inserting row, when edited not showing file , 1 time again asking file upload. here controller:
public function addclient() { $logo = 'logo'; $status = ""; $msg = ""; $file_extension = ""; $this->load->library('form_validation'); $this->form_validation->set_rules('name','name','trim|required'); $this->form_validation->set_rules('location', 'location', 'trim|required'); $this->form_validation->set_rules('address', 'address', 'trim|required'); $this->form_validation->set_rules('mobile', 'mobile', 'trim|required'); $this->form_validation->set_rules('landline', 'land line', 'trim|required'); $this->form_validation->set_rules('personname', 'contact person name','trim|required'); $this->form_validation->set_rules('persondesignation', 'contact person designation', 'trim|required'); $this->form_validation->set_rules('personmobile','contact person mobile','trim|required'); $this->form_validation->set_rules('email','email address','trim|required'); $this->form_validation->set_rules('personemail','contact person email address','trim|required'); $this->form_validation->set_rules('otherinfo','other information','trim|required'); //$this->form_validation->set_rules('logo','logo','trim'); $this->form_validation->set_rules('url','website url','trim|required'); if($this->form_validation->run() == false) { $status = 'error'; echo $msg = validation_errors(); //echo json_encode(array('st'=>0, 'msg' => validation_errors())); } /******* extracting file extension ********/ $org_filename = $_files['logo']['name']; //$path_parts = pathinfo($org_filename); //$file_extension = $path_parts['extension']; $file_extension = pathinfo($org_filename, pathinfo_extension); /***** end extracting file extension ******/ $config['upload_path'] = './uploads/client'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 1024 * 1000; $final_file_name = $config['file_name'] = 'client_'.time().'.'.$file_extension; $this->load->library('upload', $config); if (!$this->upload->do_upload($logo)) { $error = $this->upload->display_errors(); echo $error; //echo json_encode($error); } else { //...save values database $this->load->model('vadmin/clientmodel','',true); $this->clientmodel->addupadteclientform($final_file_name); $status = 'success'; echo 'submitted ok...!'; } }
here model function:
public function get($client_id) { $sql = "select * ".tb_clients." client_id='".$client_id."'"; $ex = $this->db->query($sql); homecoming $ex->row_array(); } public function addupadteclientform($final_file_name = '') { $name = $this->input->post('name'); $location = $this->input->post('location'); $address = $this->input->post('address'); $mobile = $this->input->post('mobile'); $landline = $this->input->post('landline'); $personname = $this->input->post('personname'); $persondesignation = $this->input->post('persondesignation'); $personmobile = $this->input->post('personmobile'); $email = $this->input->post('email'); $personemail = $this->input->post('personemail'); $otherinfo = $this->input->post('otherinfo'); $partnerflag = $this->default_client_partner_flag; $logodisplayflag = $this->default_client_logo_display_flag; $logo = $final_file_name; $url = $this->input->post('url'); $status = $this->default_client_status ; $client_id = $this->input->post('id'); if(is_numeric($client_id) && $client_id > 0) { //mysql_real_escape_string or addslashes() //edit query $sql = "update ".tb_clients." set client_name='".mysql_real_escape_string($name)."',client_location='".mysql_real_escape_string($location)."',client_address='".mysql_real_escape_string($address)."',client_mobile='".mysql_real_escape_string($mobile)."',client_landline_number='".mysql_real_escape_string($landline)."',client_contact_person_name='".mysql_real_escape_string($personname)."',client_contact_person_designation='".mysql_real_escape_string($persondesignation)."',client_contact_person_mobile='".mysql_real_escape_string($personmobile)."',client_email_address='".mysql_real_escape_string($email)."',client_contact_person_email_address='".mysql_real_escape_string($personemail)."',client_other_info='".mysql_real_escape_string($otherinfo)."',partner_flag='".mysql_real_escape_string($partnerflag)."',logo_display_flag='".($logodisplayflag)."',logo='".mysql_real_escape_string($logo)."',client_website_url='".mysql_real_escape_string($url)."',status='".mysql_real_escape_string($status)."' client_id='".mysql_real_escape_string($client_id)."'" ; echo $sql; } else { $sql = "insert ".tb_clients." (client_name,client_location,client_address,client_mobile,client_landline_number,client_contact_person_name,client_contact_person_designation,client_contact_person_mobile,client_email_address,client_contact_person_email_address,client_other_info,partner_flag,logo_display_flag,logo,client_website_url,status) values (".$this->db->escape(trim($name)).",".$this->db->escape(trim($location)).",".$this->db->escape(trim($address)).",".$this->db->escape(trim($mobile)).",".$this->db->escape(trim($landline)).",".$this->db->escape(trim($personname)).",".$this->db->escape(trim($persondesignation)).",".$this->db->escape(trim($personmobile)).",".$this->db->escape(trim($email)).",".$this->db->escape(trim($personemail)).",".$this->db->escape(trim($otherinfo)).",".$this->db->escape(trim($partnerflag)).",".$this->db->escape(trim($logodisplayflag)).",".$this->db->escape(trim($logo)).",".$this->db->escape(trim($url)).",".$this->db->escape(trim($status)).")"; homecoming $this->db->query($sql); } }
you running query when if(is_numeric($client_id) && $client_id > 0)
false
else part running query
change
homecoming $this->db->query($sql); }
to
} // move homecoming $this->db->query($sql);
php jquery mysql codeigniter
Comments
Post a Comment