php - update statement breaking the database -
i trying figure out what's wrong here, not sure. have site users, when user edits details, seems override other records details. doesn't happen (of course result chaos!). here code of update
public function update_edit() { /* echo " //// inside update edit "; */ $this->form_validation->set_rules('fullname', 'الاسم الكامل', 'isset|required|min_length[6]|max_length[100]'); //check there no form validation errors if($this->form_validation->run() == false) { /* echo " //// inside form validation"; */ if(($this->session->userdata('username')!="")) { /* echo " //// inside session validation"; */ $data = array(); $data = $this->profilemodel->load_user_editable_data($this->session->userdata('username')); $this->load->view('layout/header'); $this->load->view('profile_edit', $data); $this->load->view('layout/footer'); //$this->load->view('thankyou'); }else{ //$this->load->view('login'); $this->login(); } }else{ $complete = $this->profilemodel->update_profile($this->session->userdata('username')); if($complete == 1) { $this->load->view('layout/header'); $this->load->view('update_complete'); $this->load->view('layout/footer'); } } }
this model code:
public function update_profile($username) { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $this->load->library('upload', $config); $fullimagepath; if (isset($_files['profilepic']) && !empty($_files['profilepic']['name'])) { if ($this->upload->do_upload('profilepic')) { $upload_data = $this->upload->data(); $fullimagepath = '/uploads/' . $upload_data['file_name']; } }else{ $fullimagepath = $this->session->userdata('profilepic'); } $data = array( 'fullname' => $this->input->post('fullname'), 'email' => $this->input->post('email'), 'mobile' => $this->input->post('mobile'), 'telephone' => $this->input->post('telephone'), 'about' => $this->input->post('about'), 'address' => $this->input->post('address'), 'profilepic' => $fullimagepath, ); $this->db->where('username', $username); $this->db->update('free_user_members', $data); return 1; }
and form:
<div class="content_container"> <div id="rt-main" class="mb8-sa4"> <div class="rt-container"> <div class="rt-grid-12"> <div dir="rtl" class="homecontent"> <?php echo validation_errors(); ?> <?php echo form_open_multipart('profile/update_edit'); ?> <? $this->session->set_userdata('profilepic', $profilepic); ?> <h5>الاسم الكامل</h5> <? $data = array( 'name' => 'fullname', 'id' => 'round_input', 'value' => $fullname, ); echo form_input($data); ?> <h5>الايميل</h5> <? $data = array( 'name' => 'email', 'id' => 'round_input', 'value' => $email, 'size' => '70' ); echo form_input($data); ?> <h5>الجوال</h5> <? $data = array( 'name' => 'mobile', 'id' => 'round_input', 'value' => $mobile, ); echo form_input($data); ?> <h5>هاتف</h5> <? $data = array( 'name' => 'telephone', 'id' => 'round_input', 'value' => $telephone, ); echo form_input($data); ?> <h5>العنوان</h5> <? $data = array( 'name' => 'address', 'id' => 'round_input', 'value' => $address, 'size' => '70' ); echo form_input($data); ?> <h5>نبذة عني</h5> <? $data = array( 'name' => 'about', 'id' => 'round_input', 'value' => $about, 'rows' => '3', 'cols' => '40', ); echo form_textarea($data); ?> <h5>الصورة الشخصية</h5> <img width="300" height="300" src="<? echo $profilepic; ?>" /> <h5>إختيار صورة جديدة</h5> <? $data = array( 'name' => 'profilepic', 'id' => 'profilepic', ); echo form_upload($data); ?> <div><input type="submit" value="احفظ التغييرات" /></div> </form> </div> <p> </p> </div> </div> <div class="clear"></div> </div> </div>
will appreciate if tells me doing lead chaos every , then.
regards,
you have add code check username in session exists.
if session times out, codeigniter return false
.
querying mysql on username = false
return rows.
Comments
Post a Comment