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);
	}
}
?>

Leave a Reply

Related Posts: You may like

Codeigniter pagination with search query string

Minify HTML in CodeIgniter using Hooks

Redirect http to https using htaccess

How to execute mysql query inside codeigniter helper

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.