php - Update a database record using codeigniter -
i have been having problem... frustrating problem @ that. i cannot seem edit specific row in codeigniter. have found previous questions on same here, , tried solutions no avail. press time on project undertaking. before regard question duplicate please have see. any appreciated... thank in advance code snippets below:
codeigniter/controller
<?php.. //selects admin table function get_admin(){ $data['query'] = $this->superuser_model->selectadmin(); } //brings in view // function editadmin(){ // $data['content'] = 'admin/edit_admin'; // $this->load->view('include/template_back', $data); // } //click specific row in view (tabulated data) function edit($id){ $data['array']= $this->superuser_model->editadmin($id); // $data['content'] = 'admin/edit_admin'; $this->load->view('include/header_back'); $this->load->view('admin/edit_admin', $data); $this->load->view('include/footer_back'); } //should update function update_superuser(){ $this->form_validation->set_rules('username','username','required'); $this->form_validation->set_rules('password','password','required'); if($this->form_validation->run()==false) { $data['content'] = 'admin/add_admin'; $this->load->view('include/template_back', $data); } else { $username = $this->input->post('username'); $password = md5($this->input->post('password')); $date_added = $this->input->post('date_added'); $this->superuser_model->update_superuser($username,$password,$date_added); redirect('login/index', 'refresh'); } } ..?>
codeigniter/model
<?php... function selectadmin(){ // $id = $this->uri->segment(3); $query = $this->db->get('admin'); return $query->result_array(); } function editadmin($id){ $id = $this->uri->segment(3); $query = $this->db->get('admin'); $this->db->where('adminid', $id); return $query->result_array(); } function update_superuser($data, $id){ $this->uri->segment(3); $id = $this->input->post('adminid'); $data = array( 'username'=> $this->input->post('username'), 'password'=> $this->input->post('password'), 'date_added'=> $this->input->post('date_added') ); $this->db->where('adminid', $id); $this->db->update('admin', $data); } ...?>
codeigniter/view ...
<?php echo form_open('superuser/update_superuser', array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data')); ?> <div class="panel panel-default"> <div class="panel-heading"> <div class="panel-btns"> <a href="#" class="panel-close">×</a> <a href="#" class="minimize">−</a> </div> <h4 class="panel-title">admin details</h4> <p>please, insert details here below... (for superuser use only)</p> </div> <div class="panel-body panel-body-nopadding"> <!--username--> <div class="form-group"> <!-- <input type="hidden" name="adminid" class="form-control" value="<?php echo $array->adminid;?>"/> --> <label class="col-sm-4 control-label">username</label> <div class="col-sm-8"> <input type="text" name="username" class="form-control" value="<?php echo $array['username'];?>"/> </div> // <?php // form_error('username');?> </div> <!--password--> <div class="form-group"> <label class="col-sm-4 control-label">password</label> <div class="col-sm-8"> <input type="password" name="password" class="form-control" value="<?php echo $array['password'];?>"/> </div> <?php //echo form_error('date_added');?> </div> <!--date added--> <div class="form-group"> <label class="col-sm-4 control-label">date</label> <div class="col-sm-8"> <input type="text" name="date_added" class="form-control" id="datepicker" value="<?php echo $array['date_added'];?>" /> <img src="<?php echo base_url();?>components/backend/images/calendar.gif" alt="" /><br /><br /> </div> <?php //echo form_error('date_added');?> </div> </div><!-- panel-body --> <div class="panel-footer"> <button class="btn btn-primary">submit</button> <button type="reset" class="btn btn-default">reset</button> </div><!-- panel-footer --> </div><!-- panel-default --> <?php form_close();?> ...</body></html>
errors displayed
a php error encountered severity: notice message: undefined index: username filename: admin/edit_admin.php line number: 54 php error encountered severity: notice message: undefined index: password filename: admin/edit_admin.php line number: 62 php error encountered severity: notice message: undefined index: date_added filename: admin/edit_admin.php line number: 70
seems not correct $array['username']
, $array['password']
, $array['date_added']
. print out $array
first , you'll see what's wrong.
Comments
Post a Comment