Codeigniter registration system with session

Today we are going to show you how to create a codeigniter registration forn and save form data into database in simple way. Here we are explaining step by step how can we create simple effective codeigniter registration system.

We learned about codeigniter registration system in previous article of codeigniter.
This codeigniter registartion system is tested and working fine in case if you getting any kind of errors and not understanding how to implement feel free and comment as soon as possible we will back to you.

Step 1. Create view name of “registration.php” inside (application/views) folder

<?php
/*
	Author: Mukesh Jakhar
	Description: User registration view
*/
defined('BASEPATH') OR exit('No direct script access allowed');
$this->load->helper('url');
?>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>User registration form</title>
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
	<div class="col-md-3"></div>
		<div class="col-md-6">
			<h2>User registration form</h2>
			<?php if(isset($msg)){echo $msg;}?>
			<form method="post" enctype="multipart/form-data">
				<div class="form-group">
					<label>Name</label>
					<input class="form-control" type="text" name="name" />
				</div>
				<div class="form-group">
					<label>Email</label>
					<input class="form-control" type="text" name="email" />
				</div>
				<div class="form-group">
					<label>Phone Number</label>
					<input class="form-control" type="text" name="phone" />
				</div>
				<div class="form-group">
					<label>Password</label>
					<input class="form-control" type="text" name="password" />
				</div>
				<div class="form-group">
					<input class="btn btn-primary" type="submit" value="Publish" />
				</div>
			</form>
		</div>
	</div>
</body>
</html>

Step 2. Create Controller name of “User_registration.php” inside (application/controllers) folder

<?php
/*
	Author: Mukesh Jakhar
	Description: User registration controller class
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class User_registration extends CI_Controller {
	function __construct() {
		parent::__construct();
		$this->load->library('form_validation');
		$this->load->model('Registartion_model');
	}
	public function index()
	{
		if($this->input->post('name'))
		{
			$formData = array(
				'name' => $this->input->post('name'),
				'email' => $this->input->post('email'),
				'phone' => $this->input->post('phone'),
				'password' => $this->input->post('password')
			);
			$this->Registartion_model->add_new_user($formData);
			$res['msg']="New user has been added!";
			$this->load->view('registration', $res);
		}
		else
		{
			$this->load->view('registration');
		}
	}
}

Step 3. Create model name of “Registartion_model.php” inside (application/models) folder

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
	Author: Mukesh Jakhar
	Description: User registration model class
*/
class Registartion_model extends CI_Model{
	function __construct(){
		$this->load->database();
		parent::__construct();
	}

	function add_new_user($formData){
		$this->db->insert('users', $formData);
	}
}
?>
Mukesh Jakhar - PHP Web Developer
Mukesh Jakhar

This is Mukesh Jakhar. I’m a professional web developer with 3+ years experience. I am always ready for freelance work and i am writing blogs in my free time. I love to learn new technologies and share with others.

I founded PHPKIDA in September 2015. The focus of this website to provide web development tutorials of PHP, WordPress, CodeIgniter, Jquery, MySQL, HMTL, CSS etc and sharing solution to problems which i already solved.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.