Welcome Guest, Not a member yet? Register   Sign In
Unable to insert data into database
#1

[eluser]Unknown[/eluser]
According to example given in code ignitor tutorials when i submit the news data is not displaying in database.

<?php
class News extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}

public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';

$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}

public function view($slug)
{
$data['news_item'] = $this->news_model->get_news($slug);

if (empty($data['news_item']))
{
show_404();
}

$data['title'] = $data['news_item']['title'];

$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}

//check whether the form was submitted and values are passed to database or not
public function create(){

$this->load->helper('form');
$this->load->library('form_validation');
$data['title']='Create a news item';
$this->form_validation->set_rules('title','title','required');
$this->form_validation->set_rules('text','text','required');

if($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header',$data);
$this->load->view('news/create');
$this->load->view('templates/footer');

}
else
{

$this->news_model->set_news();
// display success web page
$this->load->view('news/success');
//echo("News is added successfully");
}

}
}
?>.

#2

[eluser]CroNiX[/eluser]
You should post your news_model:Confusedet_news(), since that's where the db insertion is taking place.




Theme © iAndrew 2016 - Forum software by © MyBB