php - Update record in database using codeigniter -
hi there iam using codeigniter , have managed post id number , phone number table named "offers" both fields int, when try update phone number corresponding specific id see no changes in database. have listed controller , model , view below
newoffer controller
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); //insert data db using offer_model model // other option update submit class newoffer extends ci_controller { function addoffer() { //if form submitted $this->load->view("check"); $this->load->model("offer_model"); if ($this->input->post('mysubmit')) { $this->offer_model->entry_insert(); } } function updateoffer (){ $this->load->view("check2"); $this->load->model("offer_model"); if ($this->input->post('mysubmit')) { $this->offer_model->upddata(); } } } ?>
offer_model
class offer_model extends ci_model{ public function entry_insert(){ $data = array( 'idnum' => $this->input->post('idnum'), 'phnenum' => $this->input->post('phnenum'), ); $this->db->insert('offers',$data); } public function upddata($data) { $this->db->where('idnum', $idnum); $this->db->update('data' ,$data); //extract($data); //$data['offername'] //$this->db->where('offername' , $data['offername']); //$this->db->update($offers, array('offername' => $offername)); return true; } } ?>
the view update values
<?form _open(base_url()."index.php/newoffer/updateoffer")?> <div class="form"> // <?php echo form_open('newoffer/addoffer'); ?> <legend>please enter details new offer</legend> <label for="id number">id number: <span class="required">*</span></label> <input type="text" name="idnum" id="idnum" placeholder="please enter id number/> <label for="phone number">phone number:</label> <input type="text" name="phnenum" id="phnenum " placeholder="please enter phone number"/> <fieldset class="submit_field"> <?php echo form_submit('mysubmit', 'submit form'); ?> </fieldset> </div><!-- end of form div --> ?>
you aren't passing data model here
$this->offer_model->upddata();
you need add like
$this->offer_model->upddata($this->input->post());
also in model code $idnum
undefined need provide too.
e.g:
public function upddata($data) { $idnum = $data['idnum']; unset($data['idnum']); $this->db->where('idnum', $idnum); $this->db->update('offers' ,$data); return true; } //etc
Comments
Post a Comment