Welcome Guest, Not a member yet? Register   Sign In
Trying to update database with textarea...
#1

I'm trying to update my database with a textarea (name=postNote). But whenever I press the save button it saves a "0" in the request_notes field in the database no matter what I type in. Here is my view...
Code:
<?php
   foreach($rows as $r){
    $data[] = $r->Submitted;
       if ($notes){
           foreach($notes as $n){
?>
           <p>Notes are for internal use/collaboration only</p>
           <table class="detail">
               <tr>
                   <td><textarea name="postNote" rows="8" cols="80"><?php echo $n->request_notes; ?></textarea><br>
               </tr>
           </table>    
           <br />
           <table class="detail">
               <tr>
                   <td><div data-ot="This will save changes made to notes" data-ot-delay="1"><?php echo anchor("main/saveNotes/$r->Submitted", 'Save changes', 'class="button icon arrowdown"'); ?></div></td>
               </tr>
           </table>
<?php
           }
       } else {
?>
           <p>Notes are for internal use/collaboration only</p>
           <table class="detail">
               <tr>
                   <td><textarea name="postNote" rows="8" cols="80"></textarea><br>
               </tr>
           </table>
           <br />
           <table class="detail">
               <tr>
                   <td><div data-ot="This will save changes made to notes" data-ot-delay="1"><?php echo anchor("main/saveNotes/$r->Submitted", 'Save changes', 'class="button icon arrowdown"'); ?></div></td>
               </tr>
           </table>
<?php
       }
   }
?>
and here is my controller ....
Code:
   public function saveNotes(){
    $this->load->model('model_data');
    if($this->model_data->isNote()){
        //the row exists so call the update function from the model
        $this->model_data->updateNotes();
      
    } else {
        //the row doesnt exist yet, call the insert functon from the model
        $this->model_data->insertNotes();
        
    }
    $this->request_details();
   }
and here is my model...
Code:
function isNote(){
       $this->db->where('submit_time', $this->uri->segment(3));
       $query = $this->db->get('apps_request_notes');
       
       if ($query->num_rows() == 1){
           return true;
       } else {
           return false;
       }
   }
   
   function updateNotes(){
       $data = array(
        'request_notes' => $this->input->post('postNote')
    );
       $this->db->where('submit_time', $this->uri->segment(3));
    $this->db->update('apps_request_notes', $data);
   }
   
   function insertNotes(){
       $data = array(
        'request_notes' => $this->input->post('postNote'),
               'submit_time' => $this->uri->segment(3)
    );
       
    $this->db->insert('apps_request_notes', $data);
   }
Not sure whats happening. Its not giving me any errors or anything. It just always saves "0" when I press save. Thanks for any help you can give.
Reply


Messages In This Thread
Trying to update database with textarea... - by alexandervj - 11-19-2014, 11:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB