0

I have a problem about update or edit a particular data in one to many relationship. Here is the picture->error

In my database I have a "Idcertificate" that is primary key and I have also "Id" a foreign key. Here is my picture -> enter image description here

this is my view:

    <div class="modal fade" id="myModals" role="dialog">
                <div style="margin-top: 100px;" class="modal-dialog modal-lg">
   
                    <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title text-center">Certificates and Awards</h4>
        </div>
        <div class="modal-body">
      
			
           
                <?php 
              if ( isset($message) ){
         echo   $message;

   } else{  
    foreach ($r as $index => $r)
    {
      
                  ?>
              <form method="POST" action="<?php echo site_url("certificates/editon/".$r->Id)  ?>">
                  <input  class="input-lg " type="hidden" name="Id" placeholder="<?php echo $r->Id  ?>"   readonly=""> 
                  <input  class="input-lg " type="hidden" name="Idcertificate" placeholder="<?php echo $r->Idcertificate  ?>"   readonly=""> 
                <input class="input-lg  text-capitalize"   type="text" name="AwardsReceived" placeholder="Certificates/Awards Received" value="<?php echo $r->Certificates ?>" >
              
                <input class="input-lg text-capitalize"  type="text" name="Year" placeholder="Year" value="<?php echo $r->Year?>">
                <input class="input-lg  text-capitalize"   type="text" name="Place" placeholder="Place" value="<?php echo $r->Place ?>">
    <?php } } ?>
                        
      
                <br><br> <div class="modal-footer"> 
          
       <button type="submit" class="btn btn-default" >Update</button> 
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> 
           </div>
           
             </form> 
        </div>
      </div>
    </div>
  </div>
            

this is my controller:

 function editon($Id){
       
       
           
    
            
             $data= Array(
                 'Idcertificate' => $this->input->post('Idcertificate'),
                 'Certificates' => $this->input->post('AwardsReceived'),
                 'Year'      => $this->input->post('Year'), 
                 'Place'  => $this->input->post('Place'),
                 );
              $this->db->where('Id', $Id);
              $this->db->update('certificatesawardsreceived',$data);
              redirect('viewstudentinalpha/index');
    }
}

1
  • Bit strange. Can you post table schema. Blind shot could be default value set to 0. Primary key should be AUTO_INCREMENT NOT NULL and you shouldn't make post of it. DB by itself need to increase value for next row. Commented Feb 5, 2016 at 1:48

1 Answer 1

1

Try using (int)

$data= array(
  'Idcertificate' => $this->input->post('Idcertificate'),
  'Certificates' => (int)$this->input->post('AwardsReceived'),
  'Year' => $this->input->post('Year'), 
  'Place'  => $this->input->post('Place'),
);

$this->db->where('Id', $Id);

$this->db->update('certificatesawardsreceived',$data);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you sir ! @wolfgang1983

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.