Step : 1 First Download CodeIgniter_2.1.3c
Step :2 Create Table
CREATE TABLE IF NOT EXISTS `ci_users` (
`id_users` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(255) NOT NULL,
`artist` varchar(100) NOT NULL,
PRIMARY KEY (`id_users`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
Step : 3 Set Database Configuration path:(application/config/database.php)
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'codeigniter';
Step : 4 Create Controller PHP file name is signup.php path:(application/controllers/signup.php)
signup.php
==>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class signup extends CI_Controller
{
public function index()
{
$this->load->helper(array('form', 'url'));
//////// Form Validation Library Load //////////
$this->load->library('form_validation');
///////// Session Library Load //////////////////
$this->load->library('session');
////////// Check Validation Form ////////////////
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
$this->form_validation->set_rules('username', 'username', 'required|min_length[3]|max_length[12]|trim');
$this->form_validation->set_rules('password', 'password', 'required|min_length[2]|md5');
$this->form_validation->set_rules('email', 'email', 'required|valid_email|trim');
$this->form_validation->set_rules('artist', 'artist', 'max_length[32]|trim');
if(!$this->form_validation->run())
{
$this->load->view('signupform');
}
else
{
///////// Database Liberary Load //////
$this->load->database();
///////// Model Call for Data Insert /////
$this->load->model('signup_model');
/////////// Username already Exists or not Check Here //////////////////
$user_name = $this->signup_model->duplicate_usercheck($this->input->post('username'));
if($user_name == 0)
{
////////// Data Insert Function call //////
$this->signup_model->signup_user();
/////////// If data is Insert then Set Success Message //////
$data['message'] = "<font class='success'>Registration Successfully..!!</font>";
}else
{
/////////// If Duplicate Entry in database then Set Error Message //////
$data['message'] = "<font class='error'>Username is Allready in Database..!!</font>";
}
$this->load->view('signupform',$data);
}
}
}
?>
Step : 5 Create Model PHP file name is signup_model.php path:(application/models/signup_model.php)
signup_model.php
==>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class signup_model extends CI_Model {
function signup_user()
{
$data['username'] = $this->input->post('username');
$data['password'] = sha1($this->input->post('password'));
$data['email'] = $this->input->post('email');
$data['artist'] = $this->input->post('artist');
$this->db->insert('ci_users', $data);
}
function duplicate_usercheck($username)
{
$q = $this->db->select('username')
->from('ci_users')
->where(array('username' => $username))->get();
return $q->num_rows();
}
}
?>
Step : 6 Create View PHP file name is signupform.php path:(application/views/signupform.php)
signupform.php
==>
<style>
h1{
color:#369;
text-align:center;
}
h3{
color:#C39;
}
table{
border:2px solid #0CF;
border-radius:10px;
}
th{
text-align:left;
}
input[type="submit"],[type="reset"]
{
background-color:#000;
color:#FFF;
}
.error{
color:#F00;
}
.success{
color:#00F;
}
</style>
<?php echo form_open('signup'); ?>
<h1>Registration Form</h1>
<table cellpadding="10" cellspacing="10" align="center">
<?php
if(@$message)
{
?>
<tR>
<td colspan="3" align="center"><?php echo $message;?></td>
</tR>
<?php
}
?>
<tR>
<td colspan="3"><h3>Account information</h3></td>
</tR>
<tR>
<th><label for="username">Choose a username <span class="required">*</span></label></th>
<td><input type="text" name="username" id="username" value="<?php echo set_value('username'); ?>" class="contact_textfield"/><br><span><?php echo form_error('username'); ?></span></td> </tR>
<tR>
<th><label for="password">Pick a password <span class="required">*</span></label></th>
<td><input type="password" name="password" class="contact_textfield"/><br><span><?php echo form_error('password'); ?></span></td>
</tR>
<tR>
<th><label for="email">Enter your valid email address <span class="required">*</span></label></th>
<td><input type="text" name="email" id="email" value="<?php echo set_value('email'); ?>" class="contact_textfield"/><br><span><?php echo form_error('email'); ?></span></td> </tR>
<tR>
<td colspan="3"><h3>About you</h3></td>
</tR>
<tR>
<th><label for="band">Who's your favorite artist?</label></th>
<td><input type="text" name="artist" value="<?php echo set_value('artist'); ?>" class="contact_textfield"/> <br><span><?php echo form_error('artist'); ?></span></td> </tR>
<tR>
<td colspan="2" class="height45"><input type="submit" value="Register" class="big_btn dark"/> <input type="reset" value="Reset" class="big_btn dark"></td>
</tR>
</table>
<?php echo form_close(); ?>
Step : 7 Run in Browser Like this http://localhost/codeIgniter/index.php/signup
Step :2 Create Table
CREATE TABLE IF NOT EXISTS `ci_users` (
`id_users` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(255) NOT NULL,
`artist` varchar(100) NOT NULL,
PRIMARY KEY (`id_users`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
Step : 3 Set Database Configuration path:(application/config/database.php)
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'codeigniter';
Step : 4 Create Controller PHP file name is signup.php path:(application/controllers/signup.php)
signup.php
==>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class signup extends CI_Controller
{
public function index()
{
$this->load->helper(array('form', 'url'));
//////// Form Validation Library Load //////////
$this->load->library('form_validation');
///////// Session Library Load //////////////////
$this->load->library('session');
////////// Check Validation Form ////////////////
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
$this->form_validation->set_rules('username', 'username', 'required|min_length[3]|max_length[12]|trim');
$this->form_validation->set_rules('password', 'password', 'required|min_length[2]|md5');
$this->form_validation->set_rules('email', 'email', 'required|valid_email|trim');
$this->form_validation->set_rules('artist', 'artist', 'max_length[32]|trim');
if(!$this->form_validation->run())
{
$this->load->view('signupform');
}
else
{
///////// Database Liberary Load //////
$this->load->database();
///////// Model Call for Data Insert /////
$this->load->model('signup_model');
/////////// Username already Exists or not Check Here //////////////////
$user_name = $this->signup_model->duplicate_usercheck($this->input->post('username'));
if($user_name == 0)
{
////////// Data Insert Function call //////
$this->signup_model->signup_user();
/////////// If data is Insert then Set Success Message //////
$data['message'] = "<font class='success'>Registration Successfully..!!</font>";
}else
{
/////////// If Duplicate Entry in database then Set Error Message //////
$data['message'] = "<font class='error'>Username is Allready in Database..!!</font>";
}
$this->load->view('signupform',$data);
}
}
}
?>
Step : 5 Create Model PHP file name is signup_model.php path:(application/models/signup_model.php)
signup_model.php
==>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class signup_model extends CI_Model {
function signup_user()
{
$data['username'] = $this->input->post('username');
$data['password'] = sha1($this->input->post('password'));
$data['email'] = $this->input->post('email');
$data['artist'] = $this->input->post('artist');
$this->db->insert('ci_users', $data);
}
function duplicate_usercheck($username)
{
$q = $this->db->select('username')
->from('ci_users')
->where(array('username' => $username))->get();
return $q->num_rows();
}
}
?>
Step : 6 Create View PHP file name is signupform.php path:(application/views/signupform.php)
signupform.php
==>
<style>
h1{
color:#369;
text-align:center;
}
h3{
color:#C39;
}
table{
border:2px solid #0CF;
border-radius:10px;
}
th{
text-align:left;
}
input[type="submit"],[type="reset"]
{
background-color:#000;
color:#FFF;
}
.error{
color:#F00;
}
.success{
color:#00F;
}
</style>
<?php echo form_open('signup'); ?>
<h1>Registration Form</h1>
<table cellpadding="10" cellspacing="10" align="center">
<?php
if(@$message)
{
?>
<tR>
<td colspan="3" align="center"><?php echo $message;?></td>
</tR>
<?php
}
?>
<tR>
<td colspan="3"><h3>Account information</h3></td>
</tR>
<tR>
<th><label for="username">Choose a username <span class="required">*</span></label></th>
<td><input type="text" name="username" id="username" value="<?php echo set_value('username'); ?>" class="contact_textfield"/><br><span><?php echo form_error('username'); ?></span></td> </tR>
<tR>
<th><label for="password">Pick a password <span class="required">*</span></label></th>
<td><input type="password" name="password" class="contact_textfield"/><br><span><?php echo form_error('password'); ?></span></td>
</tR>
<tR>
<th><label for="email">Enter your valid email address <span class="required">*</span></label></th>
<td><input type="text" name="email" id="email" value="<?php echo set_value('email'); ?>" class="contact_textfield"/><br><span><?php echo form_error('email'); ?></span></td> </tR>
<tR>
<td colspan="3"><h3>About you</h3></td>
</tR>
<tR>
<th><label for="band">Who's your favorite artist?</label></th>
<td><input type="text" name="artist" value="<?php echo set_value('artist'); ?>" class="contact_textfield"/> <br><span><?php echo form_error('artist'); ?></span></td> </tR>
<tR>
<td colspan="2" class="height45"><input type="submit" value="Register" class="big_btn dark"/> <input type="reset" value="Reset" class="big_btn dark"></td>
</tR>
</table>
<?php echo form_close(); ?>
Step : 7 Run in Browser Like this http://localhost/codeIgniter/index.php/signup
No comments:
Post a Comment