I have these codes:



class Site extends CI_Controller
    function index()
        $data = array();

        $records = $this->site_model->get_records();
        if (count($records) > 0)
            $data['records'] = $query;

        $this->load->view('admin/options_view', $data);

    function create()
        $data = array(
            'title' => $this->input->post('title'),
            'content' => $this->input->post('content')

        if (true) $this->index(); //added check if something returned from model




class Site_model extends CI_Model {

    function get_records()
        $query = $this->db->get('data');
        return $query->result();

    function add_record($data)
        $this->db->insert('data', $data);

    function update_record($data)
        $this->db->where('id', 14);
        $this->db->update('data', $data);

    function delete_row()
        $this->db->where('id', $this->uri->segment(3));




<!DOCTYPE html>

<html lang="en">
    <style type="text/css" media="screen">
        label {display: block;}
    <?php echo form_open('site/create');?> 

         <label for="title">Title:</label>
         <input type="text" name="title" id="title">

         <label for="content">Content:</label>
         <input type="text" name="content" id="content">

         <input type="submit" value="Submit">

    <?php echo form_close(); ?>


    <?php if(isset($records)) : foreach($records as $row) : ?>

    <h2><?php echo $row->title; ?></h2>
    <div><?php echo $row->content; ?></div>

    <?php endforeach; ?>

    <?php else : ?>  
    <h2>No records were returned</h2> 
    <?php endif ; ?>


After I input the title and content and press submit, it starts to bring me to this url:


(it shows the first page and nothing happens)

Instead of saving the data and display it on Read.

$records = $this->Site_model->get_records();//Capital
  1. Try without using PHP shorthands in view,
  2. Post autoload.php file
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.