Welcome Guest, Not a member yet? Register   Sign In
unable to update record
#11

(07-30-2016, 11:52 AM)we don\t need the following to close the form, with out these now its working. Wrote:
Code:
echo form_close();
or

Code:
</form>


(07-30-2016, 11:37 AM)pid=\335273 Wrote:hi InsiteFX,

mwhitney also mentioned that there is some problem with <form> please check the following and suggest.


PHP Code:
<!DOCTYPE html
<
html lang "en">
 
 
  <head
 
     <meta charset "utf-8"
 
     <title>Students Example edit</title
 
  </head
    
 
  <body
 
     <form method "" action "">
        
 
        <?php 
            echo form_open
('Stud_controller/update_student'); 
 
           echo form_hidden('old_roll_no',$old_roll_no); 
 
           echo form_label('Roll No.'); 
 
           echo form_input(array('id'=>'roll_no','name'=>'roll_no','value'=>$records[0]->roll_no));
 
           echo "<br/>"
                
 
           echo form_label('Name'); 
 
           echo form_input(array('id'=>'name','name'=>'name','value'=>$records[0]->name));
 
           echo "<br/>"
                
 
           echo form_submit(array('id'=>'submit','value'=>'Edit')); 
 
           echo form_close();
            echo 
$this->db->last_query();
 
        ?> 
            
      </form> 
   </body>
    
</html> 

There should be no quotes its an integer
Reply
#12

@nadeem14375: What's you question? Your post only contains quotes from earlier posts, right?
Reply
#13

(07-30-2016, 11:08 PM)thanks Wouter60, I am new so, these are stupid questions. can you guide me to some templates that I can easily implement to build forms? Wrote: @nadeem14375: What's you question? Your post only contains quotes from earlier posts, right?
Reply
#14

(This post was last modified: 07-31-2016, 09:48 AM by Wouter60.)

There are probably more roads to the same solution, but I'll try to describe the approach that is most common in CI.
This is a very basic example, using model, view and controller.

Controller: Stud_controller
PHP Code:
public function update_student($id)
{
   
$this->load->model('stud_model');
 
  if ( ! $this->input->post('submit') ) {
 
       // if the form is not yet submitted, then show the form
 
       $data['record'] = $this->stud_model->get_student($id);
 
       $this->load->view('student_form',$data);
 
  }
 
  else {
 
       // form is submitted; update the record in the database
 
       $data = array(
 
           'name' => $this->input->post('name'),
 
           'roll_no' => $this->input->post('roll_no')
 
       );
 
       $this->stud_model->update_student($id,$data);
 
       redirect('/');  //return to your home page
 
  }


Model: stud_model
PHP Code:
public function get_student($id)
{
//fetch a record from the table 'students', for the given id
$query $this->db->get_where('students''id=' $id1);
if (
$query->num_rows() > 0) {
 
  return $this->query->row_array();
}
else {
 
  return FALSE;
}
}

public function 
update_student($id,$data)
{
//update the record in the table 'students'
$this->db->update('students'$data'id=' $id);


View student_form
PHP Code:
<?php 
if (! $record) {
 
   show_error('There is no student with this id in the database');
 
   die();
}
echo 
form_open();  //the form will be submitted to the same url as it was called from
echo 'Name: ' form_input('name',$record['name']) . '<br />';
echo 
'Roll_no: ' form_input('roll_no'$record['roll_no']) . '<br />';
echo 
form_submit('submit','Submit form');  //important: the submit button should have a name, in this case: 'submit'
echo form_close();
?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB