How to create Registration form
Step 1 : Unzipped the downloaded codeigniter file and copy the inside folder and paste into the htdocs and rename it with registration
Step 2. Renamed the file with registration, now our project name is registration
Step 3 : Open your Xampp and start the Apache and MySQL
Step 4 : Open the browser and run the below url ,registration is your project name
http://localhost/registration/
Step 5 : Setup the configuration:
Copy the url of http://localhost/registration/ from your browser and paste it into config file, config file path is given. Path : registration\application\ config
Go to line base url and paste your copied url
$config['base_url'] = 'http://localhost/ registration/';
Then save it
Step 6 : Setup the configuration in autoload also
Path : registration >> application >> config >> autoload
set the below line in libraries and helper
$autoload['libraries'] = array("database","session"," form_validation");
$autoload['helper'] = array("url","form");
Then save it
Step 7 : Setup the configuration in database
Before you setup the database config you must create your database in localhost/phpmyadmin create your database name = "registration" and table name="users" add column user_id, first_name, last_name, mobile.
After Successfully creation of your database and table. set you configuration
Path : registration >> application >> config >> database
Open database file, you can set your username and password its depend upon you but for a while follow username and password and database name = "registration"
Then save it
Step 8 : Create Controller :
Go to application >> controllers >> Welcome
Remove Earlier code and Paste following code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->form_validation->set_rules("first_name","First Name","trim");
$this->form_validation->set_rules("last_name","Last Name","trim");
$this->form_validation->set_rules("mobile","Mobile","trim");
if($this->form_validation->run() == FALSE)
{
$this->load->view('welcome_message');
}
else
{
$first_name =$this->input->post("first_name");
$last_name =$this->input->post("last_name");
$mobile =$this->input->post("mobile");
$table_name="users";
$insert_data=array(
"first_name"=>$this->input->post("first_name"),
"last_name"=>$this->input->post("last_name"),
"mobile"=>$this->input->post("mobile")
);
$this->load->model('Mregistration','',TRUE);
$insert_result=$this->Mregistration->insert_master($table_name,$insert_data,$return_type="");
if($insert_result)
{
$msg = "Success";
}
else
{
$msg = "failed";
}
redirect("result/result_page/".$msg, 'refresh');
}
}
}
?>
Step 9 : Create Model :
Go to application >> model
and create new model with Mregistration.php and save it in application >> model >> Mregistration.php
Paste following code
<?php
class Mregistration extends CI_Model
{
function insert_master($table_name,$insert_data,$return_type="")
{
$this->db->insert($table_name,$insert_data);
$db_error_arr = $this->db->error();
$error_number=$db_error_arr["code"];
if($error_number!=0)
{
$error_message=$db_error_arr["message"];
log_message('error', $error_message);
$output["status"]=FALSE;
$output["err"]=1;
$output["data"] = array();
return $output;
}
if($return_type=="insert_id"){
return $this->db->insert_id();
}
else{
return true;
}
}
}
?>
Step 10 : Create View :
Create new view file and name it as registration_view.php inside application >> views >> registration_view.php and save it
Paste following code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration Form</title>
</head>
<body>
<form method="post" action="<?php echo base_url().""; ?>" >
<div id="container">
<h1>Registration Form</h1>
<div id="body">
<label>Firstname : </label>
<input class="form-control" type="text" placeholder="Firstname" name="first_name" id="first_name" value="<?php echo set_value('first_name'); ?>" />
<span class=" text-danger"><?php echo form_error("first_name"); ?></span><br/><br/>
<label>Lastname : </label>
<input class="form-control" type="text" placeholder="Lastname" name="last_name" id="last_name" value="<?php echo set_value('last_name'); ?>" />
<span class=" text-danger"><?php echo form_error("last_name"); ?></span><br/><br/>
<label>Mobile : </label>
<input class="form-control" type="text" name="mobile" id="mobile" value="<?php echo set_value('mobile'); ?>" />
<span class=" text-danger"><?php echo form_error("mobile"); ?></span><br/><br/>
</div>
<button class="btn btn-sm btn-success" type="submit" name="submit" >Save</button>
</div>
</body>
</form>
</html>
Step 11: Run the Project :
Run the url http://localhost/registration/
Step 12 : Done
Back to Codeigniter simple project
Step 1 : Unzipped the downloaded codeigniter file and copy the inside folder and paste into the htdocs and rename it with registration
Step 3 : Open your Xampp and start the Apache and MySQL
Step 4 : Open the browser and run the below url ,registration is your project name
http://localhost/registration/
Step 5 : Setup the configuration:
Copy the url of http://localhost/registration/ from your browser and paste it into config file, config file path is given. Path : registration\application\
Go to line base url and paste your copied url
$config['base_url'] = 'http://localhost/
Then save it
Step 6 : Setup the configuration in autoload also
Path : registration >> application >> config >> autoload
set the below line in libraries and helper
$autoload['libraries'] = array("database","session","
$autoload['helper'] = array("url","form");
Then save it
Step 7 : Setup the configuration in database
Before you setup the database config you must create your database in localhost/phpmyadmin create your database name = "registration" and table name="users" add column user_id, first_name, last_name, mobile.
After Successfully creation of your database and table. set you configuration
Path : registration >> application >> config >> database
Open database file, you can set your username and password its depend upon you but for a while follow username and password and database name = "registration"
Then save it
Step 8 : Create Controller :
Go to application >> controllers >> Welcome
Remove Earlier code and Paste following code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->form_validation->set_rules("first_name","First Name","trim");
$this->form_validation->set_rules("last_name","Last Name","trim");
$this->form_validation->set_rules("mobile","Mobile","trim");
if($this->form_validation->run() == FALSE)
{
$this->load->view('welcome_message');
}
else
{
$first_name =$this->input->post("first_name");
$last_name =$this->input->post("last_name");
$mobile =$this->input->post("mobile");
$table_name="users";
$insert_data=array(
"first_name"=>$this->input->post("first_name"),
"last_name"=>$this->input->post("last_name"),
"mobile"=>$this->input->post("mobile")
);
$this->load->model('Mregistration','',TRUE);
$insert_result=$this->Mregistration->insert_master($table_name,$insert_data,$return_type="");
if($insert_result)
{
$msg = "Success";
}
else
{
$msg = "failed";
}
redirect("result/result_page/".$msg, 'refresh');
}
}
}
?>
Step 9 : Create Model :
Go to application >> model
and create new model with Mregistration.php and save it in application >> model >> Mregistration.php
Paste following code
<?php
class Mregistration extends CI_Model
{
function insert_master($table_name,$insert_data,$return_type="")
{
$this->db->insert($table_name,$insert_data);
$db_error_arr = $this->db->error();
$error_number=$db_error_arr["code"];
if($error_number!=0)
{
$error_message=$db_error_arr["message"];
log_message('error', $error_message);
$output["status"]=FALSE;
$output["err"]=1;
$output["data"] = array();
return $output;
}
if($return_type=="insert_id"){
return $this->db->insert_id();
}
else{
return true;
}
}
}
?>
Step 10 : Create View :
Create new view file and name it as registration_view.php inside application >> views >> registration_view.php and save it
Paste following code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration Form</title>
</head>
<body>
<form method="post" action="<?php echo base_url().""; ?>" >
<div id="container">
<h1>Registration Form</h1>
<div id="body">
<label>Firstname : </label>
<input class="form-control" type="text" placeholder="Firstname" name="first_name" id="first_name" value="<?php echo set_value('first_name'); ?>" />
<span class=" text-danger"><?php echo form_error("first_name"); ?></span><br/><br/>
<label>Lastname : </label>
<input class="form-control" type="text" placeholder="Lastname" name="last_name" id="last_name" value="<?php echo set_value('last_name'); ?>" />
<span class=" text-danger"><?php echo form_error("last_name"); ?></span><br/><br/>
<label>Mobile : </label>
<input class="form-control" type="text" name="mobile" id="mobile" value="<?php echo set_value('mobile'); ?>" />
<span class=" text-danger"><?php echo form_error("mobile"); ?></span><br/><br/>
</div>
<button class="btn btn-sm btn-success" type="submit" name="submit" >Save</button>
</div>
</body>
</form>
</html>
Step 11: Run the Project :
Run the url http://localhost/registration/
Step 12 : Done
Back to Codeigniter simple project

No comments: