I am inserting data which i would delete and update later on the same page.I have a problem with the route and path,(base url) for the views and controllers.i get page 404 saying page cant be found.
What I have tried:
the is controller
<?php
class Main extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->database();
}
public function index()
{
$this->load->model('main_model');
$this->load->view('main_view',$data);
}
public function form_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name',"First Name", 'required|alpha');
$this->form_validation->set_rules('last_name',"Last Name", 'required|alpha');
if ($this->form_validation->run())
{
$this->load->model('main_model');
$data = array
(
"first_name" =>$this->input->post('first_name'),
"last_name" =>$this->input->post('last_name')
);
$this->main_model->insert_data($data);
redirect (base_url() . "main/inserted");
}
else
{
$this->index();
}
}
public function inserted()
{
$this->index();
}
}
this is the view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Insert Data To Database</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<br /><br /><br />
<h3 align="center">Insert Data</h3><br />
<form method="post" action="<?php echo base_url(); ?>main/form_validation">
<?php
if ($this->uri->segment(2) == "inserted")
{
echo '<p class="text-success">Data Inserted </p>';
}
?>
<div class="form-group">
<label>Enter First Name</label>
<input type="text" name="first_name" class="form-control" />
<span class="text-danger"><?php echo form_error('first_name');?></span>
</div>
<div class="form-group">
<label>Enter Last Name</label>
<input type="text" name="last_name" class="form-control" />
<span class="text-danger"><?php echo form_error('last_name');?></span>
</div>
<br />
<div class="form-group">
<input type="submit" name="insert" value="Insert" class="btn btn-info" />
</div>
</form>
</div>
</body>
</html>
this is my base url
$config['base_url'] = 'http://127.0.0.2:8383/tuts';
this is my route configuration,main.php is the controller i defined above
$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;