How to Update Textarea Value in CodeIgniter

How to Update Textarea Value in CodeIgniter

In this example we will show how to update textarea value in codeigniter. You can learn simple example of update textarea value using codeigniter. In this post we will discuss on codeigniter update textarea value.

I will provide example of how to update textarea value using codeigniter. After read this post you can simply update your textarea value in codeigniter.

Example : Update Textarea Value using CodeIgniter

Create Controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class DemoController extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('demo');
    }
    
    function demo(){
        if(!empty($_POST)){

            $array = array(
                "message" => $this->input->post("message")
            );

            $this->db->where('id', $this->input->post("id"));
            $this->db->update("demo",$array);

            redirect('/democontroller/demo');
        }
        $data['demo'] = $this->demo->get_row_by_id('demo', array("id"=>1));

        $this->load->view('demo',$data);
    }
}

Create Model

<?php

class Demo extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function get_row_by_id($table_name,$where_array){
        $this->db->select("*");
        $this->db->from($table_name);
        $this->db->where($where_array);
        $query = $this->db->get();
        if ($query->num_rows() > 0){
            return $query->row();
        }else{
            return false;
        }
    }
    
}

Create Controller

<!DOCTYPE html>
<html lang="en">
<head>
  <title>How to Update Textarea Value in CodeIgniter - Web-tuts.com</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Update Textarea Value using CodeIgniter - Web-tuts.com</h2>

  <form method="post">

    <div class="form-group">
      <label for="message">Message:</label>
      <input type="hidden" name="id" value="<?= $demo->id ?>">
      <textarea class="form-control" id="message" placeholder="Enter message" name="message"><?= $demo->message ?></textarea>
    </div>
    
    <button type="submit" class="btn btn-primary">Update</button>
  </form>
</div>

</body>
</html>

I hope you understand of how to update textarea value with codeigniter and can help you…