简体   繁体   中英

How to update input field values in codeigniter

I am a beginner in Codeigniter and using version 3 I am performing update operation so I have store data and now I have created a separate form for update and want to set this form inputs values that are stored in databases

My View (update.php)

```<div class="form-group"> 
<label for="exampleInputEmail1">Title</label>
 <?php echo form_input(['name'=>'title', 'placeholder'=>'Enter title',
 'class'=>'form-control col- md-5',
 'value'=>set_value('title','$post->title')]);?>
 </div>```

My COntroller

public function update($id)
    {

        $this->load->model('queries');
    $postt=$this->queries->getSinglePosts($id); 

    $post=$postt->title;

        $this->load->view('update',['post'=>$post]);

    }

My Model

public function getSinglePosts($id) { $query=$this->db->get_where('tbl_posts',array('id'=>$id));

        if ($query->num_rows() >0 ) {
        return $query->row();
    }

}

Because you've used set_value('title','$post->title')]); in your view file, I think you should remove this line from your controller $post=$postt->title; and you should pass the whole of $postt variable to your view (make sure that the $postt is not an array of objects).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM