[eluser]mirag3[/eluser]
Hi, i have this code but it doesnt insert query into db or redirect to congrats_view. Alltime its getting only index function. Where is the problem? Thanks..
Controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Add_entry extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('add_entry_model');
}
function index()
{
$this->load->view('add_entry_view');
}
function add()
{
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
if($this->form_validation->run() == FALSE)
{
redirect('/add_entry/index');
}
else
{
$this->add_entry_model->add_entry();
//redirect('/add-entry/congrats');
}
}
public function congrats()
{
$this->load->view('congrats_view');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>
Model
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Add_entry_model extends CI_Model {
function __construct()
{
parent::__construct();
}
function add_entry()
{
$data = array(
'id' => '',
'name' => $this->input->post('name'),
'email' => $this->input->post('email')
);
$this->db->insert('entries',$data);
}
}
?>
View
Code:
<?php echo form_open("add_entry/add"); ?>
<input type="text" id="name" name="name" />
<input type="text" id="email" name="email" />
<input type="submit" />
<?php echo form_close(); ?>