Welcome Guest, Not a member yet? Register   Sign In
adding data to the database
#1

My data is not going into the table in my database. I am just getting null entries.

This is my model:
Code:
[php]  <?php
  
  class Site_model extends CI_Model{
   /*
      function getAll(){
          $q = $this->db->get('test');
      
      
      if($q->num_rows() > 0){
      
          foreach ($q->result() as $row){
          
              $data[] = $row;  
              
          }
      
          
                return $data;  
      
        }
          
    }
    */
    function get_records()
    {
        $query = $this->db->get('data');
        return $query->result();
    }
    
    function add_record($data)
    {
        $this->db->insert('data', $data);
        return;
    }
    
    function update_record($data)
    {
        $this->db->where('id',1);
        $this->db->update('data', $data);
    }
    
    function delete_row()
    {
        $this->db->where('id', $this->uri->segment(3));
        $this->db->delete('data');
    }
      

  
}
[/php]

This is my controller:

Code:
[php]
<?php

class Site extends CI_Controller{

    function index()
    {
    
        //$data['myValue'] = "Some string";
        //$data['anotherValue'] = "Another string";
        
        /*$this->load->model('data_model');
        $data['row'] = $this->data_model->getAll();
        //$this->site_model->getAll();
        $this->load->view('home', $data);
        */
        $this->load->view('options_view');
        
        
    }
    
    function create()
    {
    $data = array(
    'title' => $this->input->post('title'),
    'contents' => $this->input->post('contents')
        );
        
        $this->site_model->add_record($data);
        
        $this->index();
    }
    
}
[/php]

This is my view:
Code:
[php]
<!DOCTYPE html>

<html lang = "en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled</title>
<style type="text/css" media="screen">
label {display:block;}
</style>
</head>
<body>
    <h2>Create</h2>
    <?php echo form_open('site/create');  ?>
    
    <p>
        <label for="title">Title</label>
        <input type="text" id="title" id="title" />
    </p>
    
    <p>
        <label for="title">Content:</label>
        <input type="text" name="contents" id="contents" />
    </p>
    
    <p>
        <input type="submit" id="contents" />
    </p>
    <?php echo form_close(); ?>
</body>
</html>
[/php]
Reply


Messages In This Thread
adding data to the database - by Ben - 02-16-2015, 09:48 PM
RE: adding data to the database - by RobertSF - 02-16-2015, 11:07 PM
RE: adding data to the database - by Ben - 02-17-2015, 11:55 AM
RE: adding data to the database - by RobertSF - 02-17-2015, 02:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB