hi, am here again. I did some house cleaning on my previous code and am still having issues with my form validation(dunnoe if that's really the cause). Am creating a bus reservation system as a school project and am av created a registration form for a user with a controller called user.php with function called register_user(). I also have a model named model_user.php with a function insert_user() . My view file is view_register.php and if a user successfully fills and submits the form a view_register_success is supposed to appear telling the user that the have successfully registered for an account. Now that doesn't happen instead a 404 page appears and this is how this url in the browser appears
http://localhost/busticket/user/user/register_user, i have no idea on what to do. Please help!!
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('model_user');
}
public function index()
{
$this->register_user();
}
public function register_user()
{
$this->load->library('form_validation');
//$this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span>', '</div>');
$data['title'] = 'Register';
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|min_length[3]|max_length[15]');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|min_length[3]|max_length[15]');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[6]|max_length[15]|is_unique[user.username]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[6]|max_length[30]|valid_email|is_unique[user.email]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[20]|matches[password_conf]');
$this->form_validation->set_rules('password_conf', 'Confirm Password', 'required|min_length[6]|max_length[20]');
if ( $this->form_validation->run() === FALSE) {
$this->load->view('templates/header', $data);
// $this->load->view('templates/navigation');
$this->load->view('frontend/view_register');
$this->load->view('templates/footer');
}
else
{
$this->model_user->insert_user();
//echo 'good';
//$this->load->view('templates/header');
//$this->load->view('templates/navigation');
$this->load->view('frontend/view_register_success');
//$this->load->view('templates/footer');
}
}
}
---------------------------------------------------
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h4>User Registration Form</h4>
</div>
<div class="panel-body">
<form action="user/register_user" method="post">
<div class="form-group">
<label for="name">First Name</label>
<input class="form-control" name="firstname" placeholder="Your First Name" type="text" value="<?php echo set_value('firstname'); ?>"/>
<span class="text-danger"><?php echo form_error('firstname'); ?></span>
</div>
<div class="form-group">
<label for="name">Last Name</label>
<input class="form-control" name="lastname" placeholder="Last Name" type="text" value="<?php echo set_value('lastname'); ?>" />
<span class="text-danger"><?php echo form_error('lastname'); ?></span>
</div>
<div class="form-group">
<label for="name">Username</label>
<input class="form-control" name="lastname" placeholder="Username" type="text" value="<?php echo set_value('username'); ?>" />
<span class="text-danger"><?php echo form_error('username'); ?></span>
</div>
<div class="form-group">
<label for="email">Email ID</label>
<input class="form-control" name="email" placeholder="Email-ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="form-group">
<label for="subject">Password</label>
<input class="form-control" name="password" placeholder="Password" type="password" />
<span class="text-danger"><?php echo form_error('password'); ?></span>
</div>
<div class="form-group">
<label for="subject">Confirm Password</label>
<input class="form-control" name="password_conf" placeholder="Confirm Password" type="password" />
<span class="text-danger"><?php echo form_error('password_conf'); ?></span>
</div>
<div class="form-group">
<button name="submit" type="submit" class="btn btn-default">Signup</button>
<button name="cancel" type="reset" class="btn btn-default">Cancel</button>
</div>
</form>
-------------------------------------------------------
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'home';
$route['user/register'] = 'user/register';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
---------------------------------------------------------
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Model_user extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function insert_user()
{
$data = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
);
$this->db->insert('user', $data);
}
}