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

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

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");

        if($this->form_validation->run() == FALSE)

            $first_name =$this->input->post("first_name");
            $last_name =$this->input->post("last_name");
            $mobile =$this->input->post("mobile");




                $msg = "Success";
                $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

class Mregistration extends CI_Model
    function insert_master($table_name,$insert_data,$return_type="")

        $db_error_arr = $this->db->error();
            log_message('error', $error_message);
             $output["data"] = array();
             return $output;

            return $this->db->insert_id();
            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 

defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <title>Registration Form</title>   

<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/>

    <button class="btn btn-sm  btn-success" type="submit" name="submit" >Save</button>


Step 11: Run the Project :
Run the url http://localhost/registration/

Step 12 :  Done

 Back to Codeigniter simple project
Reviewed by Admin on March 20, 2020 Rating: 5

No comments:

Powered by Blogger.