Tuesday, 24 March 2015

Registration form in codeIgniter

registration.php (view)
==============================
<html>
<head>
    <title>
        Registration
    </title>
</head>
<body>
<form method="post" action="<?php echo base_url() ?>/index.php/welcome/insert" enctype="multipart/form-data">
    <table border="1">

        <tr>
            <th>Fname</th>
            <td><input type="text" name="fname" </td>
        </tr>
        <tr>
            <th>sname</th>
            <td><input type="text" name="sname"></td>
        </tr>
        <tr>
            <th>Lname</th>
            <td><input type="text" name="lname"></td>
        </tr>
        <tr>
            <th>Gender</th>
            <td>
                <input type="radio" name="gender" value="male">Male
                <input type="radio" name="gender" value="female">Female
            </td>
        </tr>
        <tr>
            <th>Hobby</th>
            <td><input type="checkbox" name="hob[]" value="read">READ
            <input type="checkbox" name="hob[]" value="cri">Cricket
            </td>
        </tr>
        <tr>
            <th>Image</th>
            <td><input type="file" name="file"></td>
        </tr>

        <tr>
            <td><input type="submit" value="Add"></td>
            <td><a href="<?php echo base_url() ?>/index.php/welcome/login">Login</a> </td>
        </tr>

    </table>

</form>
</body>
</html>

======================
conroller 
======================

public function index()   {
            $this->load->view('registration');

   }

    function insert()    {        if(@$this->session->userdata('id'))        {            header("Location:".base_url()."/index.php/welcome");        }        else        {            $data=$_POST;//            echo '<pre>';//            print_r($data);//            die;            $this->load->model('model1','mod');            $config['upload_path']   = './uploads/';            $config['allowed_types'] = 'gif|jpg|png';            $config['max_size']      = '1024';            $config['max_width']     ='15555';            $config['max_height']    ='15555';            $this->load->library('upload',$config);
                if(!$this->upload->do_upload('file'))                {                    $error=$this->upload->display_errors();
                }            else{
                $img=$this->upload->data();
            }            $data['file']=$img['file_name'];            $get=$this->mod->ins($data);            $sessi=$get['id'];            $this->session->set_userdata('id',$sessi);            $data=$this->session->userdata('id');            header("Location:".base_url()."/index.php/welcome");

        }

    }
    function login()    {        $this->load->view('login');    }
=======================
model model1.php
=======================

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class model1 extends CI_Model{
    function ins($data)    {//        echo '<pre>';//        print_r($data);//        die;
        $data['hob']=$data['hob'][0].','.$data['hob'][1];        $this->db->insert('registration',$data);        echo '<script>alert("insert");</script>';        header('location:http://localhost/CodeIgniter_mitul//index.php/welcome');    }
}
?>

No comments:

Post a Comment