php - Using flashdata to determine if model was successful in CodeIgniter -


i trying determine if database update performed in model successful, pass status of (successful or not successful) view can display div appropriately. far, it's worked long model update worked, not working when it's not. i'm using flashdata pass data through controller.

my model:

public function editticket($ticket) {     $q = $this->db->where('ticketid', $ticket['ticketid']);     $q = $this->db->update('tickets', $ticket);     $results = $this->db->affected_rows();      return $results; } 

my controller:

public function editexistingticket() {     $this->load->model('tickets');     $date = date("y-m-d h:i:s");     $ticket = array(         'ticketid'    => $this->input->post('ticketid'),         'category'    => $this->input->post('category'),         'headline'    => $this->input->post('headline'),         'description' => $this->input->post('description'),         'assigned'    => $this->input->post('assigned'),         'status'      => $this->input->post('status'),         'priority'    => $this->input->post('priority'),         'lastupdated' => $date     );     if ($this->tickets->editticket($ticket)){         $this->session->set_flashdata('edit', '1');     } else {         $this->session->set_flashdata('edit', '0');     } } 

my view (the relevant parts):

var edited = '<?php echo $this->session->flashdata('edit'); ?>';  if (edited == '1') {   $('#editmessage').slidedown('slow');   settimeout(function(){$('#editmessage').slideup('slow')}, 3000);   //sessionstorage.setitem('edit', '0'); } else if (edited == '2') {   $('#editfailmessage').slidedown('slow');   settimeout(function(){$('#editfailmessage').slideup('slow')}, 3000);   //sessionstorage.setitem('edit', '0'); } 

any ideas on did wrong?

thanks help!

well, in controller setting flashdata 0 if ticket updated unsuccessfully:

$this->session->set_flashdata('edit', '0');

but can see in view expecting variable visited 2:

} else if (edited == '2') {

and error box appear.

you should fix values , think fine.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -