title: Data check in database if already exist in codeigniter through ajax
body: <p>I want to check data in database through ajax in codeigniter how can get check name already exist through ajax </p>
  
  <h2>controller</h2>
  
  <pre><code>public function insert(){
      $user = array('Name' =&gt; $this-&gt;input-&gt;post('name'), 
                    'Cnic' =&gt; $this-&gt;input-&gt;post('cnic'),
                    'Phone' =&gt; $this-&gt;input-&gt;post('phone'),
                    'Address' =&gt; $this-&gt;input-&gt;post('address'),
          );
      $this-&gt;load-&gt;model('suppliermodel');
      if($this-&gt;suppliermodel-&gt;checkData($user['Name'])){
          if ($this-&gt;session-&gt;userdata('user_id'))
            $detail = 'Already exist';
        $this-&gt;load-&gt;view('admin/includes/header');
        $this-&gt;load-&gt;view('admin/includes/sidemenu');
        $this-&gt;load-&gt;view('admin/add_supplier',['exist'=&gt;$detail]);
        $this-&gt;load-&gt;view('admin/includes/footer');
        $this-&gt;load-&gt;view('admin/includes/add_supplier_footer');
  
      }
      else{
       $this-&gt;suppliermodel-&gt;add($user);  
      }
  
  }
  </code></pre>
  
  <h2>model</h2>
  
  <pre><code>public function checkData()
  {
    $name = $this-&gt;input-&gt;post('name');
    $this-&gt;db-&gt;select('*');
    $this-&gt;db-&gt;where('Name', $name);
    $this-&gt;db-&gt;from('suppliers');
    $query = $this-&gt;db-&gt;get();
    if($query-&gt;num_rows() &gt;0){
      return $query-&gt;result();
    }
    else{
      return $query-&gt;result();
      return false;
    }
  }
  </code></pre>
  
  <p>what is ajax code and controller function</p>