Monday, 20 June 2016

login Codeigneter

<?php
class login extends CI_controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('dblogin');
    }
    function index()
    {
       
       
        $this->form_validation->set_rules('username','Username','required');
        $this->form_validation->set_rules('password','Password','required');
       
        $this->form_validation->set_error_delimiters("<div class ='error'>");
        if($this->form_validation->run()==false)
        {
          $data['msg']='';       
        }
        else
        {
            $result=$this->dblogin->chklogin($_POST['username'],$_POST['password']);
           
            if($result)
            {
                $this->session->set_userdata('username',$_POST['username']);
                $data['msg']='Login Sucess';
                $this->session->set_flashdata(array('msg'=>'sucess','type'=>'Login Is Sucess'));
               
                redirect('abc');

            }
            else
            {
                $data['msg']='Login Invalid';
            }
           
        }
        $this->load->view('login_form',$data);
            }
           
        function forget()
        {   
            $this->form_validation->set_rules('username','username','required');
            if($this->form_validation->run()==false)
            {
                $data['msg']='';
            }
            else
            {
                $re=$this->dblogin->chkuser($_POST['username']);
                if($re)
                {
                  $pass=$this->dblogin->chkpass($_POST['username']);
                  $getpass=$pass->password;
                   $data['msg']=("<script language='javascript'>alert('Your Password Is....$getpass')</script>");
                }
                    else
                {
                    $data['msg']='User Wrong';
                }
            }
                $this->load->view('forget',$data);
            }
   
}



?>

ControllerInsertUpdateDelete

<?php
class abc extends CI_controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('dbabc');
       
        $login=$this->session->userdata('username');
        if($login=='')
        {
            redirect('login');
        }
       
    }
    function index()
    {
        $this->form_validation->set_rules('username','Name','required|alpha');
        $this->form_validation->set_rules('password','Name','required');
        $this->form_validation->set_rules('address','Name','required');   
        $this->form_validation->set_rules('contact','Name','required|is_numeric|min_length[10]|max_length[10]');
        $this->form_validation->set_rules('email','Name','required|valid_email');
        $this->form_validation->set_rules('gender','Name','required');
        $this->form_validation->set_rules('city','Name','required');
        $this->form_validation->set_rules('hobby','Name','required');       
       
        if($this->form_validation->run()==false)
        {
          $this->load->view('form');
        }
        else
        {
            $abc['upload_path']='upload'; 
            $abc['allowed_types']='png|jpg|jpeg|gif';
           
            $this->load->library('upload',$abc);
           
            if(!$this->upload->do_upload('image'))
            {   
                $file="";
            }
            else
            {
                $file=$this->upload->file_name;
            }
           
    $abc=array('username'=>$_POST['username'],
                'password'=>$_POST['password'],
                'address'=>$_POST['address'],
                'contact'=>$_POST['contact'],
                'email'=>$_POST['email'],
                'gender'=>$_POST['gender'],
                'city'=>implode(',',$_POST['city']),
                'hobby'=>implode(",",$_POST['hobby']),
                'image'=>$file);
            $this->dbabc->insertwww($abc);
            redirect('abc/view');
        }
    }
    function view()
    {
        $data['result']=$this->dbabc->getalldata();
        $this->load->view('view',$data);
    }
    function search()
    {
        $data['result']=$this->dbabc->getsearch();
          $this->load->view('view',$data);
    }
    function delete($id)
    {
        $abc=$this->dbabc->deleteimg($id);
        unlink("upload/".$abc->image);
       
        $this->dbabc->delete($id);
        redirect('abc/view');
    }
    function edit($a)
    {
        if($a=='')
        {
            redirect('abc/view');
        }
        $this->form_validation->set_rules('username','Name','required');
        $this->form_validation->set_rules('password','Name','required');
        $this->form_validation->set_rules('address','Name','required');   
        $this->form_validation->set_rules('contact','Name','required|is_numeric|min_length[10]|max_length[10]');
        $this->form_validation->set_rules('email','Name','required|valid_email');
        $this->form_validation->set_rules('gender','Name','required');
        $this->form_validation->set_rules('city','Name','required');
        $this->form_validation->set_rules('hobby','Name','required');       
       
        if($this->form_validation->run()==false)
        {
            $data['aaa']=$a;
            $this->load->view('edit',$data);
        }
        else
        {
            $abc['upload_path']='upload'; 
            $abc['allowed_types']='png|jpg|jpeg|gif';
           
            $this->load->library('upload',$abc);
            if(!$this->upload->do_upload('image'))
            {
                $file=$_POST['old_image'];
            }
            else
            {
                $file=$this->upload->file_name;
            }
    $abc=array('username'=>$_POST['username'],'password'=>$_POST['password'],'address'=>$_POST['address'],'contact'=>$_POST['contact'],'email'=>$_POST['email'],'gender'=>$_POST['gender'],'city'=>implode(',',$_POST['city']),'hobby'=>implode(",",$_POST['hobby']),'image'=>$file);
            $this->dbabc->update($abc,$a);
            redirect('abc/view');
        }
    }
   
}

?>

Saturday, 9 January 2016

InsertUpdateDelete with Validtion

//Config.php
<?php

$cn = mysql_connect('localhost','root','') or die(mysql_error());
if(!$cn)
{
    echo "ERROR:not connected";
   
    }


$db = mysql_select_db('info') or die(mysql_error());
    if(!$db)
{
    echo "ERROR: Not Connected..";
   
    }   
?>


//Stud.php

<body>
<form action="" method="post" enctype="multipart/form-data">
  <div align="center">
    <fieldset>
      <legend>Stud-Info</legend>
       <div>
        <label>userId:-</label>
        <label>
            <input name="txtid" id="txtid" type="text" readonly="readonly"
             />
          </label>
      </div>
      <div>
        <label>Name:-<sup style="color:red">*</sup></label>
        <label>
            <input name="txtname" id="txtname" type="text" placeholder="Enater Name" />
          </label>
      </div>
     
      <br/>
      <div><input name="txtsignup" type="submit" value="Signup" onclick="return validate() " /></div>
    </fieldset>
  </div>
 
  <fieldset><legend>Griedview</legend>
  <table align="center" border="1"><caption><h3>Griedview</h3></caption>
   <tr>
  <th>userid</th>
  <th>Username</th>
  <th>Edit</th>
  <th>Delete</th>
  </tr>
  <?php
 
  $grid=mysql_query("Select * from Registration");
 
  //echo "<table><tr><th>Id</th> <th>name</th></tr>";
  
  while($gr=mysql_fetch_row($grid))
  {
    echo "<tr>";
    echo "<td>$gr[0]</td>";   
    echo "<td>$gr[1]</td>";
      echo "<td><a href=Stud.php?did=$gr[0]>Delete</a></td>";
    echo "<td><a href=update.php?uid=$gr[0]>Edit</a></td>";
  }
 
  ?>
 
  </table>

  </fieldset>
 
</form>

</body>


//validation on head
<script language="javascript" type="text/javascript">
function validate()

{
    var x1= document.getElementById("txtname");
        if(x1.value.length==0)
        {
            alert("please Enter UserName");
            x1.focus();
           
        return false;
           
            }
    }

</script>




 <?php
include_once("config.php");
extract($_POST);
if(isset($txtsignup))
{
    $res= mysql_query("insert into Registration (userName) Values('$txtname')") or
    die(mysql_error());
       
    }
   
        if(isset($_REQUEST['did']))
    {
        mysql_query("delete from Registration where userId=".$_REQUEST['did']);
    }
?>




//Update.php
 



<?php
     include_once("config.php");

    if(isset($_REQUEST['uid']))
   {
      $res=mysql_query("select * from registration where userId=".$_REQUEST['uid']) or die(mysql_error());
   
      $r=mysql_fetch_row($res);
   }
  
   if(isset($_POST['submit']))
   { 
 mysql_query("update registration set userName = '".$_POST['fname']."'
 where userId='".$_POST['id']."'")or die(mysql_error());
      header('location:Stud.php');
     
     
   }
?>


<br>

<form id="tform" name="frm1" action="" method="post" enctype="multipart/form-data">
<div></div>
<table align="center" border="2">
<h1 align="center">Edit form</h1>
<tr>
<td>id:</td>
<td><input type="text" name="id" id="id" value="<?php echo $r[0];?>" /></td>
</tr>
<tr>
<td>first name:<sup style="color:#C30">*</sup></td>
<td><input type="text" name="fname" id="fname" value="<?php echo $r[1];?>" /></td>
</tr>
<td>
<input type="submit" name="submit" id="submit" value="edit"/>
</td></tr>
</table>
</form>


Session

//Login.php
<?php
session_start();
   
   
    if(isset($_POST['s1']))
    {
    $x=$_POST['t1'];
    $_SESSION['user']=$x;
    $y=$_POST['t2'];
   

if(isset($_SESSION['user']))
            {
                header("Location:session1.php");   
            }   
    else
        {
            echo "Sorry........";
        }
    }

?>
<form id="form1" name="form1" method="post" action="">
  <table width="300" border="1">
    <tr>
      <td width="88">User</td>
      <td width="196"><input name="t1" type="text" id="t1" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input name="t2" type="text" id="t2" /></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
        <input name="s1" type="submit" id="s1" value="Submit" />
      </div>  <div align="center"></div></td>
    </tr>
  </table>
</form>


//Session.php


<?php
session_start();
if(isset($_SESSION['user']))
{
    echo "Hi " .$_SESSION['user'];
}
?>

Cookies



<?php
if(isset($_POST['s1']))
{
    $u=$_POST['t1'];
        if(isset($_POST['c1']))
        {
            setcookie('mydt',$u,time()+60*60*24*7);
            echo "Cookies stored.........";
            echo $u;
        }
}
?>

<?php
    if(isset($cookie['mydt']))
    {
    echo $u."Cookie Retrived";
    echo ($_COOKIE['mydt']);
    echo "cookies Retrived...";
    }

?>
<form id="form1" name="form1" method="post" action="">
  <table width="300" border="1" align="center">
    <tr>
      <td width="88">User</td>
      <td width="196"><input name="t1" type="text" id="t1" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input name="t2" type="text" id="t2" /></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
          <input name="c1" type="checkbox" id="c1" value="checkbox" />
      Remember Me </div></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
        <input name="s1" type="submit" id="s1" value="Submit" />
      </div>  <div align="center"></div></td>
    </tr>
  </table>
</form>

Friday, 9 January 2015

Registration Form

  • Registration form

  1.  Database: `db1`

 Table structure for table `reg`


CREATE TABLE IF NOT EXISTS `reg` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(20) NOT NULL,
  `Photo` varchar(50) NOT NULL,
  `Userid` varchar(30) NOT NULL,
  `Password` varchar(30) NOT NULL,
  `Email` varchar(50) NOT NULL,
  `DateOfBirth` date NOT NULL,
  `City` varchar(20) NOT NULL,
  `Gender` varchar(20) NOT NULL,
  `Address` varchar(200) NOT NULL,
  `Mobile` double NOT NULL,
  `Pin` int(11) NOT NULL,
  `Hobby` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ;



 2. index.html


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RegistrationApplication</title>
<script language="javascript" type="text/javascript">
function validate()
     {
    
         var x=document.getElementById("txtName");

        if(x.value.length==0)
            {
               alert("plese enter your name");
               x.focus();
               return false;
            }

            var x1=document.getElementById("txtUser");
              if(x1.value.length==0)
                 {
                      alert("plese enter userid");
                      x.focus();
                      return false;
                 }
            var y=document.getElementById("txtPass");
            if(y.value.length==0)
            {
                alert("Password must Be Compulsary");
                y.focus();
                return false;
            }
           
            var z=document.getElementById("txtCnfPass");
            if(y.value != z.value)
            {
                alert("Password And Conform password Must be Same");
                x.focus();
                return false;
                }
            var email=document.getElementById("txtEmail");
            if(email.value.length==0)
            {
                alert("Enter Email id")
                email.focus();
                return false;
                }       
           
            var address=document.getElementById("txtareaAddress");
            if(address.value.length==0)
            {
                alert("Enter address")
                address.focus();
                return false;
                }   
               
            var Phone=document.getElementById("txtPhone");
            if(Phone.value.length==0)
            {
                alert("Enter Phone No")
                Phone.focus();
                return false;
                }   
               
            var pin=document.getElementById("txtPin");
            if(pin.value.length==0)
            {
                alert("Enter Pincode")
                pin.focus();
                return false;
                }       
               
         return true;

     }
</script>
</head>

<body>

<form  action="Reg.php" method="post" name="form1" enctype="multipart/form-data">
  <div align="center">
    <table width="400" border="1">
      <tr>
        <td bgcolor="#CC66FF" align="center" colspan="2"><h3>ApplicationForm</h3></td>
      </tr>
      <tr>
        <td>Name:-</td>
        <td><input name="txtName" id="txtName" type="text" /></td>
      </tr>
        <tr>
        <td>Photo:-</td>
        <td><input name="file1" id="file1" type="file" /></td>
      </tr>
      <tr>
        <td>UserId:-</td>
        <td><input name="txtUser" id="txtUser" type="text" /></td>
      </tr>
     
      <tr>
     
        <td>Password:-</td>
        <td><input name="txtPass" id="txtPass" type="password" /></td>
      </tr>
      <tr>
        <td>CnfPass:-</td>
        <td><input name="txtCnfPass" id="txtCnfPass" type="password" /></td>
      </tr>
      <tr>
        <td>Email:-</td>
        <td><input name="txtEmail" id="txtEmail" type="text" /></td>
      </tr>
      <tr>
        <td>DateOfBirth:-</td>
        <td><input name="txtDateOfBirth" id="txtDateOfBirth" type="text" /></td>
      </tr>
      <tr>
        <td>City:-</td>
        <td><select name="ComboState">
            <option selected="selected" value="select">---Select---</option>
            <option>Sachin</option>
            <option>Surat</option>
            <option>Baroda</option>
            <option>Valsad</option>
            <option>Vapi</option>
          </select></td>
      </tr>
      <tr>
        <td>Gender:-</td>
        <td>
          <label>
            <input type="radio"  checked="checked" name="RadioGroup1" value="Male" id="RadioGroup1_0" />
            Male</label>
          <br />
          <label>
            <input type="radio" name="RadioGroup1" value="Female" id="RadioGroup1_1" />
            Female</label>
          <br />
        </td>
      </tr>
      <tr>
        <td>Address:-</td>
        <td><textarea name="txtareaAddress" id="txtareaAddress" cols="15" rows="2"></textarea></td>
      </tr>
     
      <tr>
        <td>PhoneNo:-:-</td>
        <td><input name="txtPhone" type="text" id="txtPhone" /></td>
      </tr>
     
      <tr>
        <td>Pincode:-</td>
        <td><input name="txtPin" type="text" id="txtPin" /></td>
      </tr>
        <tr>
        <td>Hobby:-</td>
        <td><p>
          <label>
            <input type="checkbox" name="hobbies[]" value="Tennis" />
            Tennis</label>
          <br />
          <label>
            <input type="checkbox" name="hobbies[]" value="Cricket"  />
            Cricket</label>
          <br />
          <label>
            <input type="checkbox" name="hobbies[]" value="FootBall" />
            FootBall</label>
          <br />
          <label>
            <input type="checkbox" name="hobbies[]" value="Badminten" />
            Badminten</label>
        </p></td>
      </tr>
      <tr>
<td colspan="2" align="center"><input name="Submit" type="submit" value="SignUp"
onclick="return validate()"/>
</td>       
      </tr>
    </table>
  </div>
</form>
</body>
</html>

3.config.php

<?php

mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('db1')or die(mysql_error());
?>

4. Reg.php


<?php
include_once("config.php");
if(isset($_POST['Submit']))
{
    $name=$_POST['txtName'];
    $photo=$_FILES['file1']['name'];
    move_uploaded_file($_FILES['file1']['tmp_name'],"images/$photo");
    $Userid= $_POST['txtUser'];
    $pass=$_POST['txtPass'];
    $cnfpass=$_POST['txtCnfPass'];
    $email=$_POST['txtEmail'];
    $dateofbirth=$_POST['txtDateOfBirth'];
    $city=$_POST['ComboState'];
    $gender=$_POST['RadioGroup1'];
    $Address=$_POST['txtareaAddress'];
    $phone=$_POST['txtPhone'];
    $pin=$_POST['txtPin'];
    $hobby= $_POST['hobbies'];
   
       
    for($i=0; $i<count($hobby); $i++)
        {
             $x.=$hobby[$i]."|";
        }
       
    if(strcmp('$pass','$cnfpass'))
    {
  $reg=mysql_query("insert into reg(Name,Photo,Userid,Password,Email,DateOfBirth,City,Gender,Address,
    Mobile,Pin) Values('$name','$photo','$Userid','$pass','$email','$dateofbirth','$city','$gender',
    '$Address','$phone','$pin')")or die(mysql_error());
   
    echo "Data Insert Succsessfully....";
    }
    else
    {
    echo "Password Does not Match..";
    }      
}
   
?>

 

 

Thursday, 8 January 2015

Login form

1.Login.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="login.php" method="post" name="form1">

<div align="center" >
<table width="200" border="1">
  <tr>
    <td>UserId</td>
    <td><input name="t1" type="text" /></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input name="t2" type="text" /></td>
  </tr>
  <tr>
    <td colspan="2"><input name="s1" type="submit" value="Login" /></td>
   
  </tr>

</table>
</div>
</form>
</body>
</html>

2.Login.php


<?php
include_once("config.php");
session_start();
 if(isset($_POST['s1']))
     {
    $_SESSION['user']=$_POST['t1'];
    $x=$_POST['t1'];
    $y=$_POST['t2'];
 $res=mysql_query("select * from reg where Userid='$x' and Password='$y'");
   
if(isset($_SESSION['user']))
    if(mysql_num_rows($res)>0)
            {
                 echo "Welcome".$_SESSION['user']." user";
                }else
                {
                 echo "Invalid Userid or Password ".$_SESSION['user'];
                 
                }
   
   
         }
?>