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

Monday, 23 March 2015

How to image insert and update in codeigniter.

welcome.php(controller) insert
=========================
  function insert()    {        if(@$this->session->userdata('id'))        {            header("Location:".base_url()."/index.php/welcome/timeline");        }        else        {            $data=$_POST;            $this->load->model('reg_model','mod');            //image start            $config['upload_path']          = './uploads/'; //folder name            $config['allowed_types']        = 'gif|jpg|png';            $config['max_size']             = 1002322;            $config['max_width']            = 10242323;            $config['max_height']           = 768123123;
            $this->load->library('upload', $config);            if ( !$this->upload->do_upload('file')) //file name            {                $error =  $this->upload->display_errors();
            }            else            {                $imagedata = $this->upload->data();            }            $data['file']=$imagedata['file_name']; //file is  data base filed name
//end of image            $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/timeline");        }    }
================
insert (model) 
================ 
function ins($data){    $data['hob']=$data['hob'][0].','.$data['hob'][1];    $this->db->insert('rgistration',$data);    echo '<script>alert("insert Data");</script>';    header('location:http://localhost/CodeIgniter/index.php/welcome');}

===============
 welcome.php (connroller) update
================
function alluserupdate($data1){
   $data=$_POST;    $data['hob']=$data['hob'][0].','.$data['hob'][1];  //$ses=$this->session->userdata('id');    $config['upload_path']          = './uploads/'; //folder name    $config['allowed_types']        = 'gif|jpg|png';    $config['max_size']             = 1002322;    $config['max_width']            = 10242323;    $config['max_height']           = 768123123;    $this->load->library('upload', $config);    if ( !$this->upload->do_upload('file')) //file name    {        $error =  $this->upload->display_errors();    }    else    {        $imagedata = $this->upload->data();    }

   // $imagedata['file_name']=$data['file']; //file is  data base filed name    $data['file']=$imagedata['file_name'];      $this->load->model('reg_model','mod');    $this->mod->updateq1($data,$data1);
    header("location:" .base_url()."/index.php/welcome/adminuserpro");}
==============
update in model imag 
===============
//update data    function updateq1($data,$data1)    {//        echo '<pre>';//        print_r($data1);//        die;        $this->db->where('id',$data1);        $this->db->set($data);        $this->db->update('rgistration');    }
 

Monday, 16 March 2015

How to insert multiple chackbox value in Mvc

model  query.php
=============
 function  insert($data)    {//chack box valu insert multiple    $data['c1']=$data['c1'][0].','.$data['c1'][1];
        $sql="insert into addmvc values('','".$data['txtname']."','".$data['txtmname']."','".$data['txtlname']."','".$data['txtpname']."','".$data['txtpass']."','".$data['r1']."','".$data['c1']."')";        mysql_query($sql);//        echo "hello";       // echo "<script>alert('insert');document.location='index.php?op=addform'</script>";        echo "<script>alert('insert');</script>";        header('location:index.php?op=pro');


    }

Sunday, 15 March 2015

How to Edit radio Button in mvc

First simple insert Date and Edit data for gender(radio) and simple update

============
edit.php
=============
<td><input type="radio" name="r1" value="male" <?php echo ($row1[6]=='male')?'checked':'' ?> >male
    <input type="radio" name="r1" value="femal" <?php echo ($row1[6]=='femal')?'checked':'' ?>>female</td>

MVC with insert Data Edit and delete update data with Login

index.php
===============
<?php
include_once("controller/controller.php");
$controller = new Controller();// $controller->invoke();$controller->pagehandler();
?>
============
controller.php
============
<?php
require_once('model/service.php');
    class controller {

        private  $service=null;        public function __construct() {            $this->service = new service();       }

        public function pagehandler()        {
            $op = isset($_GET['op']) ? $_GET['op'] : NULL;
            if (!$op || $op == 'a1') {                $this->doaddform();            }             elseif ($op == 'insert') {                $this->insert();          }            elseif($op == 'pro')            {                $this->profile();            }            elseif($op == 'delete')            {                $this->profiledel();            }            elseif($op== 'edit')            {                $this->profileedit();            }            elseif($op == 'update')            {                $this->profileupdate();            }            elseif($op=='login')            {
                $this->log();            }        }        //End of page Handler        function doaddform()        {            include 'view/login.php';        }        function insert()        {
            $data1=$_POST;            $this->service->insertdata($data1);        }        function profile()        {            $row1=$this->service->showpro();            include 'view/profile.php';        }        function profiledel()        {          $data=$_GET['id'];            $row11=$this->service->delpro($data);            include('view/profile.php');        }        function  profileedit()        {
            $data=$_GET['id'];
            $row1=$this->service->editpro($data);            include('view/edit.php');        }        function  profileupdate()        {
            $data=$_POST;
            $row1=$this->service->uppro($data);
        }        function log()        {            if(@$_POST)            {                $data=$_POST;                $this->service->loginchk($data);            }            else            {                include('view/profile.php');            }

        }    }?>
====================
service
====================
<?php
require_once 'model/querys.php';class service{    private $querys = NULL;
    public function __construct()    {        $this->querys = new querys();    }
    private function openDb()    {        if (!mysql_connect("localhost", "root", "")) {            throw new Exception("Connection to the database server failed!");        }        if (!mysql_select_db("mitul")) {            throw new Exception("No contacts database found on database server.");        }    }    function  insertdata($data)    {        $this->openDB();        $this->querys->insert($data);    }    function  showpro()    {        $this->openDB();        $row2=$this->querys->showprofile();
        return $row2;    }    function delpro($data)    {        $this->openDb();        $row22=$this->querys->datadel($data);        return $row22;    }    function  editpro($data)    {

        $this->openDb();        $row22=$this->querys->dataedit($data);
        return $row22;    }    function  uppro($data)    {

        $this->openDb();        $this->querys->dataup($data);

    }    function loginchk($data)    {        $this->openDb();        $this->querys->chk($data);    }}


?>

=============
model part in querys.php 
============================
<?phpclass querys {
    function  insert($data)    {        $sql="insert into addmvc values('','".$data['txtname']."','".$data['txtmname']."','".$data['txtlname']."','".$data['txtpname']."','".$data['txtpass']."')";        mysql_query($sql);//        echo "hello";       // echo "<script>alert('insert');document.location='index.php?op=addform'</script>";        echo "<script>alert('insert');</script>";        header('location:index.php?op=pro');


    }    function showprofile()    {        $sql1="select * from addmvc";        $x=mysql_query($sql1);       while($data=mysql_fetch_array($x)) {
              $row[] = $data ;       }        return $row;

    }    function  datadel($data)    {
        $sql="delete from addmvc where id='".$data."'";        mysql_query($sql);        header('location:index.php?op=pro');    }    function  dataedit($data)    {        //$sql="update addmvc set fname='".$data['txtname']."',mname='".$data['txtmname']."',lname='".$data['txtlname']."' where id='".$data."' ";        $sql="select * from addmvc where id='".$data."'";
       $data1= mysql_query($sql);        $give=mysql_fetch_array($data1);    return $give;


    }    function  dataup($data)    {        $sql="update addmvc set fname='".$data['txtfname']."',mname='".$data['txtmname']."',lname='".$data['txtlname']."',subject='".$data['txtsub']."',pass='".$data['txtpass']."' where id='".$data['hide']."' ";
        mysql_query($sql);        header('location:index.php?op=pro');




    }
//    public function check($data)//    {//        if(@$data['email']=='admin@id.com' and $data['pass']=='admin')//        {//            session_start();//            $_SESSION['id']='admin';//            header("Location:index.php?op=checktable");//        }//        else//        {//            $sql="select * from reg where email='".$data['eid']."' and pass='".$data['pass']."'";//            $result=mysql_query($sql);//            $data=mysql_fetch_array($result);//            if(@$data)//            {//                session_start();//                $_SESSION['id']=$data['rid'];//                header("Location:index.php?op=profile");//            }//        }
    function chk($data)    {       $sql="select * from addmvc WHERE  fname='".$data['txtfname']."' and pass='".$data['txtpass']."'";        $result=mysql_query($sql);        $data=mysql_fetch_array($result);        if($data)        {            header("location:index.php?op=pro");        }        else        {
            echo "wrong";        }
    }





}

?>
===============
addform.php
===============

<html>
<head>
    <title>Add Form</title>
</head>

    <body>
        <form method="post" action="index.php?op=insert"  >

            <table border="1">
                <tr>
                    <th>Fname</th>
                    <td><input type="text" name="txtname"> </td>
                </tr>
                <tr>
                    <th>Middle Name</th>
                    <td><input type="text" name="txtmname"></td>
                </tr>
                <tr>
                    <th>Last Name</th>
                    <td><input type="text" name="txtlname"></td>
                </tr>
                <tr>
                    <th>Subject</th>
                    <td><input type="text" name="txtpname"></td>
                </tr>
                <tr>
                    <th>Password</th>
                    <td><input type="password" name="txtpass"> </td>
                </tr>

                <tr>
                    <td colspan="2" align="center"><input type="submit" name="btnadd" value="ADD"></td>
                </tr>
            </table>
        </form>

    </body>


</html>
=====================
edit.php in view part
=====================
<?php
?>
<html>
<head>
    <title>
        Edit
    </title>
</head>
    <body>
        <form method="post" action="index.php?op=update">
            <table>
                <tr>
                    <th>Fname</th>
                    <th>Fname</th>
                    <th>Fname</th>
                    <th>Subject</th>
                    <th>Password</th>

                </tr>

                <tr>
                    <input type="hidden" name="hide" value="<?php echo $row1[0]; ?>">
                    <td><input type="text" name="txtfname" value="<?php echo $row1['fname']; ?>"> </td>
                    <td><input type="text" name="txtmname" value="<?php echo $row1[2]; ?>"> </td>
                    <td><input type="text" name="txtlname" value="<?php echo $row1[3]; ?>"> </td>
                    <td><input type="text" name="txtsub" value="<?php echo $row1[4];  ?>"> </td>
                    <td><input type="text" name="txtpass" value="<?php echo $row1[5]; ?>"></td>
                </tr>
                <tr>
                    <td><input type="submit" name="btnupdate"> </td>
                </tr>
            </table>

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

==================
login.php
===================
<?php?>
<html>
<head>
    <title>
        Login
    </title>
</head>
<body>
    <form name="f1" method="post" action="index.php?op=login">

        <table border="1">
            <tr>
                <th>user</th>
                <td><input type="text" name="txtfname"> </td>
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="text" name="txtpass"></td>
            </tr>
            <tr>
                <td><input type="submit" name="btnlog" value="Login"></td>
            </tr>
        </table>


    </form>


</body>

</html>
====================
profile.php
====================
<html>
<head>
    <title>SHOW</title>
</head>

<body>
<form method="post">
    <table border="1">
<!--        --><?php//        echo '<pre>';//        print_r($row1);//        die;//        ?>

            <tr>
                <th>First Name</th>
                <th>Middle Name</th>
                <th>Last Nmae</th>
                <th>Subject</th>
                <th>Password</th>
                <th>Action</th>

            </tr>
        <?php        for($i=0;$i<count($row1);$i++) {            ?>
            <tr>
                <td><?php echo $row1[$i][1]; ?></td>
                <td><?php echo $row1[$i][2]; ?></td>
                <td><?php echo $row1[$i][3]; ?></td>
                <td><?php echo $row1[$i][4]?></td>
                <td><?php echo $row1[$i][5]?></td>

                <td><a href="index.php?op=delete&&id=<?php echo $row1[$i][0] ?> ">Delete</a> </td>
                <td><a href="index.php?op=edit&&id=<?php echo $row1[$i][0] ?> ">Edit</a> </td>
            </tr>
        <?php        }?>
        <tr>
            <td colspan="4"><a href="index.php">Registration</a> </td>

        </tr>

    </table>
</form>
</body>

</html>