Sunday, 15 March 2015

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>

Friday, 13 March 2015

HOW TO IMAGE UPLODED WITH TYPE AND SIZE

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#upload").bind("click", function () {
            if (typeof ($("#fileUpload")[0].files) != "undefined") {
                var size = parseFloat($("#fileUpload")[0].files[0].size / 102400).toFixed(2);
                alert(size + " KB.");
            } else {
                alert("This browser does not support HTML5.");
            }
        });
    });
</script>
</head>

<body>
<form method="post" name="f1" enctype="multipart/form-data">

IMAGE<input type="file" name="file" id="fileUpload" />
<input type="submit" name="btnadd" id="upload" value="ADD" />



</form>
   <?php
    include('connection.php');
    if(isset($_POST['btnadd']))
{






echo $file=$_FILES['file']['name'];
$rand=rand(1,1555555);
$img=$rand.$file;
move_uploaded_file($_FILES['file']['tmp_name'],"img1/".$img);

if ((($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/jpeg"))){


//PHP Image Uploading Code

$sql=mysql_query("insert into img values('','$img')");
if(!$sql)
{
echo mysql_error();
}
else
{
echo "Done";
}
}
else
{
echo "invalid";
}
}

   ?>

Thursday, 12 March 2015

How to user profile Edit Or Update Exmple for FaceBook

Login.php
==========
<?php include('connection.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>
Login
</title>

</head>

<body>
<form name="f1" method="post">

<table border="1" align="center">
<tr>
<td colspan="3" align="center"><b>User Login</b></td>
</tr>
<tr>
<th>Email</th>
<td><input type="text" name="txtname"></td>
</tr>
<tr>
<th>Password</th>
<td><input type="text" name="txtpname"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="brnlogin" value="Login"></td>
</tr>

</table>


</form>
<?php



?>
<?php
if(isset($_POST['brnlogin']))
{
$txtname=$_POST['txtname'];

$txtpname=$_POST['txtpname'];


$sql=mysql_query("select * from task2 where email='$txtname' and confirmpass='$txtpname'");



$rows=mysql_fetch_row($sql);

if(@$rows)
{
session_start();

$_SESSION['hello']=$rows[0];


header('location:view.php');
}
else
{
echo "wrong mail id and password";
}
}
?>



</body>

</html>

==========
Logout
===========
<?php include('connection.php'); ?>
<?php session_start(); ?>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Admin</title>
</head>
<body>
<?php

unset($_SESSION['hello']);
header('location:login.php');
 ?>

</body>

</html>
=========

View.php
==========
<?php include('connection.php'); ?>
<?php session_start(); ?>
<!DOCTYPE html>

<html>
<head>
<title>User</title>
</head>

<body>
<a href="logout.php">Logout</a>
<table border="1" align="center">
<tr>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>password</th>
<th>Bod</th>
<th>Gender</th>
<th>Hobby</th>
<th>Country</th>
<th>State</th>
<th>City</th>
<th>My Image</th>
<th>Action</th>
</tr>
<?php
echo $_SESSION['hello'];
$sql=mysql_query("select * from task2 where id='".$_SESSION['hello']."'");
while($row=mysql_fetch_array($sql))
{
$id=$row[0];
?>
<tr>
<td><?php echo $row[1] ?></td>
<td><?php echo $row[2] ?></td>
<td><?php echo $row[3] ?></td>
<td><?php echo $row[4] ?></td>
<td><?php echo $row[5] ?></td>
<td><?php echo $row[6] ?></td>
<td><?php echo $row[7] ?></td>
<?php 
 $sql1=mysql_query("select * from country where id=".$row[8]."");
 
 while($row1=mysql_fetch_array($sql1))
 {
 
 
 
?>
<td><?php echo $row1['country_name']; ?></td>
<?php } ?>
<?php
$sql2=mysql_query("select * from state where stid=".$row[9]."");
while($row2=mysql_fetch_array($sql2))
{
?>
<td><?php echo $row2[1]; ?></td>
<?php } ?>
<?php
$sql3=mysql_query("select * from city where cid=".$row[10]."");
while($row3=mysql_fetch_array($sql3))
{
?>
<?php  echo "<td> <img src='imag/".$row[11]."' height=100px; width=100px;></td>";?>
<td><?php echo $row3[1]; ?></td>
<?php } ?>
<td><a href="uprofile_update.php?id=<?php echo $row[0]; ?>">Update</a></td>
<tr>
<?php
}
?>
</table>
</form>
</body>
</html>

==========================
uprofile_update.php

user profile update Only currant User
============================
<?php include('connection.php'); ?>
<!DOCTYPE html>
<html>

<head>
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function hello(str)
{
if(window.XMLHttpRequest)
            {
                   xmlhttp = new XMLHttpRequest() ; 
              }
 xmlhttp.onreadystatechange=function()
 {
 
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("msg44").innerHTML=xmlhttp.responseText;
}
 }
 xmlhttp.open("GET","2.php?id="+str,true);       
                    xmlhttp.send();       
}

</script>
<meta charset="UTF-8">



</head>

<body>
<form  method="post"  id="sub" enctype="multipart/form-data">

<a href="logout.php">Logout</a>
<table border="1">
<?php

$id=$_GET['id'];
$sql=mysql_query("select * from task2 where id=$id");
while($row=mysql_fetch_array($sql))
{

 ?>

<tr>
<th>First Name</th>
<td><input type="text" name="txtfname" id="fn" value="<?php echo $row[1]; ?>"/></td>
<td><span style='display:none;color:red' id="sp1" >enter first name</span></td>
</tr>
<tr>
<th>Last Name</th>
<td><input type="text" name="txtlname" id="fn1" value="<?php echo $row[2]; ?>" /></td>
<td><span style='display:none;color:red'  id="sp2">Enter Last name</span></td>
</tr>
<tr>
<th>Email</th>
<td><input type="text" name="txtename"  onBlur="hello(this.value)" value="<?php echo $row[3]; ?>" /></td>
<td><span id="msg44"></span></td>
</tr>
<tr>
<td>Password</td>
<td><input type='text' name='pass1' id='pass' value="<?php echo $row[4]; ?>" ></td>
<td><span style='display:none;color:red' id='sp4'>enter password</span></td>
</tr>


<tr>
<td>Re-enter Password</td>
<td><input type='text' name='pass2' id='pass2' value="<?php echo $row[4]; ?>" ></td>
<td><input type='hidden' name='checkpass' id='checkpass'>
<span style='display:none;color:red' id='sp5'>password not match</span></td>
</tr>
<tr>
<th>Date OF Birth</th>
<td><input type="date" name="dt" id="dt1" value="<?php echo $row[5]; ?>" /></td>
<td><span style='display:none;color:red' id='dt2'>pliz date selected selected</span></td>
</tr>
<tr>
<th>Gender</th>
<td>
<?php 
if($row[6]=='male')
{
echo "<input type='radio' name='g1' value='male' checked/>Male
<input type='radio' name='g1' value='female' />Female";
}
if($row[6]=='female')
{
echo "<input type='radio' name='g1' value='male' />Male
<input type='radio' name='g1' value='female' checked/>Female";
}
?>
</td>
<td><span style='display:none;color:red' id="gmsg">select gender</span></td>
</tr>
<tr>
<th>Hobby</th>
<td>
<?php 
      $m1=$row[7];
      $m2=explode(',',$m1);
      ?>
<input type="checkbox" name="c1[]" id="c1" value="cri" <?php if(in_array('cri',$m2))  { echo 'checked=checked'; } ?> />Cricket
<input type="checkbox" name="c1[]" id="c1" value="read" <?php if(in_array('read',$m2)) {echo 'checked=checked';} ?> />Read
</td>
<td><span style='display:none;color:red' id="cmsg">Select your Hobby</span></td>
</tr>
<tr>
<th>Country</th>
<td><select name="co">
<option>select</option>
<?php
$sql=mysql_query("select * from country");
while($r1=mysql_fetch_array($sql))
{
?>
<option value="<?php echo $r1[0]; ?>" <?php if($row['country']==$r1[0]) { echo 'selected=selected'; }  ?>><?php echo $r1[1]; ?></option>
<?php }
   ?>
</select>
</td>
</tr>
<tr>
<th>State</th>
<td><select name="st">
<option>Select</option>
<?php
$sql1=mysql_query("select * from state");
while($r2=mysql_fetch_array($sql1))
{
?>
<option value="<?php echo $r2[0]; ?>" <?php if($row['state']==$r2[0]) { echo 'selected=selected'; }  ?>> <?php echo $r2[1]; ?></option>
<?php }
?>
</select>
</td>
</tr>
<tr>
<th>City</th>
<td><select name="txtcity" id="txtcity" onChange="validateform()">
<option value="0">select</option>
<?php
$sql2=mysql_query("select  * from city");
while($r3=mysql_fetch_array($sql2))
{
?>
<option value="<?php echo $r3[0]; ?>" <?php if($row['city']==$r3[0]) { echo 'selected=selected'; }  ?>><?php echo $r3[1]; ?></option>
<?php }
?>
</select>
</td>
<td><span id="msg7"></span></td>
</tr>
<tr>
<th>Image</th>
<td><input type="file" name="file"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="add" value="ADD" /></td>
</tr>
<?php } ?>
</table>


</form>
<?php
if(isset($_POST['add']))
{
$txtfname=$_POST['txtfname'];
$txtlname=$_POST['txtlname'];
$txtename=$_POST['txtename'];
 $pass2=$_POST['pass2'];
$dt=$_POST['dt'];
$g1=$_POST['g1'];
$c1=implode(',',$_POST['c1']);
$co=$_POST['co'];
$st=$_POST['st'];
$txtcity=$_POST['txtcity'];
$file=$_FILES['file']['name'];
$rand=rand(1,5000000);
$img=$rand.$file;
 
move_uploaded_file($_FILES['file']['tmp_name'],"imag/".$img);
$qu=mysql_query("update task2 set fname='$txtfname',lname='$txtlname',email='$txtename',confirmpass='$pass2',bod='$dt',gender='$g1',hobby='$c1',country='$co',state='$st',city='$txtcity',img='$img' where id=$id");

if(!$qu)
{
mysql_error();
}
else
{
header('location:view.php');
}
}




 ?>
<script>
//first name
 $('#sub').submit(function(event)
 {
 
var f=$("#fn").val();
var g=$("#fn1").val();
var p=$("#pass").val();
var p2=$("#pass2").val();
var chkpass=$("#checkpass").val();
var d=$("#dt1").val();
var gnder=$("input:radio[name=g1]:checked").val();
var hob=$("input[type=checkbox]:checked").length;


         if(f=='' || g=='' || p=='' || chkpass=='1' || d=='' || gnder==undefined || hob=='0')
         {
           $("#sp1").fadeIn();
           $("#fn").css("border","1px solid red");
  $("#sp2").fadeIn();
$("#fn1").css("border","1px solid red");
$("#sp4").fadeIn();
$("#pass").css("border","1px solid red");
$("#dt2").fadeIn();
$("#dt1").css("border","1px solid red");
$("#gmsg").fadeIn();
$("#cmsg").fadeIn();
         }
          if(f=='' || g=='' || p=='' || chkpass=='1' || d=='' || gnder==undefined || hob=='0')
          {
            event.preventDefault();
          }
 });
//end of function
//keyup for first name
$("#fn").keyup(function()
{
var f=$("#fn").val();
if(f=='')
{
$("#sp1").fadeIn();
$("#fn").css("border","1px solid red");
return false;
}
else
{
$("#sp1").fadeOut();
$("#fn").css("border","1px solid black");
}
});
//keyup for last name

$("#fn1").keyup(function()
{

var g=$("#fn1").val();
if(g=='')
{
$("#sp2").fadeIn();
$("#fn1").css("border","1px solid red");
return false;
}
else
{
$("#sp2").fadeOut();
$("#fn1").css("border","1px solid black");
}
});
//pass2
$("#pass2").keyup(function()
{
var p=$("#pass").val();
var p2=$("#pass2").val();
if(p!=p2)
{
$("#sp5").fadeIn();
$("#pass").css("border","1px solid red");
$("#pass2").css("border","1px solid red");
$("#checkpass").val('1');
}
else
{
$("#sp5").fadeOut();
$("#pass").css("border","1px solid black");
$("#pass2").css("border","1px solid black");
$("#checkpass").val('0');
}
});

//pass1
$("#pass").keyup(function()
{
var p=$("#pass").val();
if(p=='')
{
$("#sp4").fadeIn();
$("#pass").css("border","1px solid red");
return false;
}
else
{
$("#sp4").fadeOut();
$("#pass").css("border","1px solid black");
}
});
//date

$("#dt").change(function()
{
var d=$("#dt1").val();

if(d=='')
{
$("#dt2").fadeIn();
$("#dt1").css("border","1px solid red");
return false;
}

else
{
$("#dt2").fadeOut();
$("#dt1").css("border","1px solid black");
}
});

//gender

$("input:radio[name=g1]").change(function()
{
var gnder=$("input:radio[name=g1]:checked").val();
if(gnder==='undefined')
{
$("#gmsg").fadeIn();
}
else
{
$("#gmsg").fadeOut();
}
});
//chackbox validation
$("input[type=checkbox]").change(function()
{
var hob=$("input[type=checkbox]:checked").length;
if(hob=='0')
{
$("#cmsg").fadeIn();
}
else
{
$("#cmsg").fadeOut();
}

});


</script>

</body>

</html>

JQUERY validation

<?php include('connection.php'); ?>
<!DOCTYPE html>
<html>

<head>
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function hello(str)
{
if(window.XMLHttpRequest)
            {
                   xmlhttp = new XMLHttpRequest() ;
              }
 xmlhttp.onreadystatechange=function()
 {

if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("msg44").innerHTML=xmlhttp.responseText;
}

 }
 xmlhttp.open("GET","2.php?id="+str,true);      
                    xmlhttp.send();      
}

</script>
<meta charset="UTF-8">



</head>

<body>
<form  method="post"  id="sub" enctype="multipart/form-data">


<table border="1">
<tr>
<th>First Name</th>
<td><input type="text" name="txtfname" id="fn"/></td>
<td><span style='display:none;color:red' id="sp1" >enter first name</span></td>
</tr>

<tr>
<th>Last Name</th>
<td><input type="text" name="txtlname" id="fn1" /></td>
<td><span style='display:none;color:red'  id="sp2">Enter Last name</span></td>
</tr>
<tr>
<th>Email</th>
<td><input type="text" name="txtename"  onBlur="hello(this.value)" /></td>
<td><span id="msg44"></span></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='pass1' id='pass'></td>
<td><span style='display:none;color:red' id='sp4'>enter password</span></td>
</tr>
<tr>
<td>Re-enter Password</td>
<td><input type='password' name='pass2' id='pass2'></td>
<td><input type='hidden' name='checkpass' id='checkpass'>
<span style='display:none;color:red' id='sp5'>password not match</span></td>
</tr>
<tr>
<th>Date OF Birth</th>
<td><input type="date" name="dt" id="dt1" /></td>
<td><span style='display:none;color:red' id='dt2'>pliz date selected selected</span></td>

</tr>
<tr>
<th>Gender</th>
<td>
<input type="radio" name="g1" value="male" />Male
<input type="radio" name="g1" value="female" />Female
</td>
<td><span style='display:none;color:red' id="gmsg">select gender</span></td>

</tr>
<tr>
<th>Hobby</th>
<td><input type="checkbox" name="c1[]" id="c1" value="cri" />Cricket
<input type="checkbox" name="c1[]" id="c1" value="read" />Read
</td>
<td><span style='display:none;color:red' id="cmsg">Select your Hobby</span></td>
</tr>
<tr>
<th>Country</th>
<td><select name="co">
<option>select</option>
<?php
$sql=mysql_query("select * from country");

while($r1=mysql_fetch_array($sql))
{
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[1]; ?></option>
<?php }
   ?>
</select>
</td>
</tr>
<tr>
<th>State</th>
<td><select name="st">
<option>Select</option>
<?php
$sql1=mysql_query("select * from state");

while($r2=mysql_fetch_array($sql1))
{
?>
<option value="<?php echo $r2[0]; ?>"> <?php echo $r2[1]; ?></option>
<?php }

?>


</select>
</td>

</tr>
<tr>
<th>City</th>
<td><select name="txtcity" id="txtcity" onChange="validateform()">
<option value="0">select</option>
<?php
$sql2=mysql_query("select  * from city");

while($r3=mysql_fetch_array($sql2))
{
?>
<option value="<?php echo $r3[0]; ?>"><?php echo $r3[1]; ?></option>
<?php }


?>
</select>
</td>
<td><span id="msg7"></span></td>
</tr>
<tr>
<th>Image</th>
<td><input type="file" name="file"></td>

</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="add" value="ADD" /></td>

</tr>

</table>


</form>
<script>
//first name
 $('#sub').submit(function(event)
 {

var f=$("#fn").val();
var g=$("#fn1").val();
var p=$("#pass").val();
var p2=$("#pass2").val();
var chkpass=$("#checkpass").val();
var d=$("#dt1").val();
var gnder=$("input:radio[name=g1]:checked").val();
var hob=$("input[type=checkbox]:checked").length;


         if(f=='' || g=='' || p=='' || chkpass=='1' || d=='' || gnder==undefined || hob=='0')
         {
           $("#sp1").fadeIn();
           $("#fn").css("border","1px solid red");
  $("#sp2").fadeIn();
$("#fn1").css("border","1px solid red");
$("#sp4").fadeIn();
$("#pass").css("border","1px solid red");
$("#dt2").fadeIn();
$("#dt1").css("border","1px solid red");
$("#gmsg").fadeIn();
$("#cmsg").fadeIn();

         }

          if(f=='' || g=='' || p=='' || chkpass=='1' || d=='' || gnder==undefined || hob=='0')
          {
            event.preventDefault();
          }
 });
//end of function
//keyup for first name
$("#fn").keyup(function()
{
var f=$("#fn").val();
if(f=='')
{
$("#sp1").fadeIn();
$("#fn").css("border","1px solid red");
return false;
}
else
{
$("#sp1").fadeOut();
$("#fn").css("border","1px solid black");
}
});
//keyup for last name

$("#fn1").keyup(function()
{

var g=$("#fn1").val();
if(g=='')
{
$("#sp2").fadeIn();
$("#fn1").css("border","1px solid red");
return false;
}
else
{
$("#sp2").fadeOut();
$("#fn1").css("border","1px solid black");
}
});
//pass2
$("#pass2").keyup(function()
{
var p=$("#pass").val();
var p2=$("#pass2").val();
if(p!=p2)
{
$("#sp5").fadeIn();
$("#pass").css("border","1px solid red");
$("#pass2").css("border","1px solid red");
$("#checkpass").val('1');
}
else
{
$("#sp5").fadeOut();
$("#pass").css("border","1px solid black");
$("#pass2").css("border","1px solid black");
$("#checkpass").val('0');
}
});

//pass1
$("#pass").keyup(function()
{
var p=$("#pass").val();
if(p=='')
{
$("#sp4").fadeIn();
$("#pass").css("border","1px solid red");
return false;
}
else
{
$("#sp4").fadeOut();
$("#pass").css("border","1px solid black");
}
});
//date

$("#dt").change(function()
{
var d=$("#dt1").val();

if(d=='')
{
$("#dt2").fadeIn();
$("#dt1").css("border","1px solid red");
return false;
}


else
{
$("#dt2").fadeOut();
$("#dt1").css("border","1px solid black");
}
});

//gender

$("input:radio[name=g1]").change(function()
{
var gnder=$("input:radio[name=g1]:checked").val();
if(gnder==='undefined')
{
$("#gmsg").fadeIn();
}
else
{
$("#gmsg").fadeOut();
}
});
//chackbox validation
$("input[type=checkbox]").change(function()
{
var hob=$("input[type=checkbox]:checked").length;
if(hob=='0')
{
$("#cmsg").fadeIn();
}
else
{
$("#cmsg").fadeOut();
}

});


</script>

<?php


if(isset($_POST['add']))
{
$fname=$_POST['txtfname'];
$lname=$_POST['txtlname'];
$txtename=$_POST['txtename'];

$txtconpass=$_POST['pass2'];
$dt=$_POST['dt'];
$gender=$_POST['g1'];
   $hobby=implode(',',$_POST['c1']);
$co=$_POST['co'];
$st=$_POST['st'];
$txtcity=$_POST['txtcity'];
$file=$_FILES['file']['name'];
$rand=rand(1,50000);
$image=$rand.$file;
move_uploaded_file($_FILES['file']['tmp_name'],"imag/".$image);

$sql=mysql_query("insert into task2 values('','$fname','$lname','$txtename','$txtconpass','$dt','$gender','$hobby','$co','$st','$txtcity','$image')");
if(!$sql)
{
echo mysql_error();
}
else
{
echo "insert";
}
}
?>
</body>

</html>

how to multiple table join for example LEFT Join

select c.country_name,s.statename,ct.cityname from country as c
left join state as s on (s.coid = c.id)
left join city as ct on (ct.stid = s.stid);

how to inner join Query

SELECT country.country_name,state.statename,state.stid
FROM country
INNER JOIN state
ON country.id=state.coid
ORDER BY country.country_name;

Tuesday, 10 March 2015

javascript validation

<!DOCTYPE html>
<html>

<head>
<title>Untitled Document</title>
<meta charset="UTF-8">
<script type="text/javascript">

function validateform()
{
//fname
   if(document.f1.txtfname.value == "")
   {
     document.getElementById("msg1").innerHTML="Enter First Name";
     document.f1.txtfname.focus();

        return false;
   }
   //txtlname
   if(document.f1.txtlname.value == "")
   {
   document.getElementById("msg2").innerHTML="Enter Last Name";
      document.f1.txtlname.focus();
   return false;
   }
   //email
    if( document.f1.txtename.value == "" )
   {
     alert( "Please provide your Email!" );
     document.f1.txtename.focus() ;
     return false;
    }
    //confirmpass
    var txtpass1 =document.getElementById("txtpass1").value;
    var txtpass2 = document.getElementById("txtpass2").value;
    if(txtpass1 != txtpass2)
    {

            document.getElementById("txtpass23").innerHTML="wrong";
            document.f1.txtpass2.focus();
            return false;
    }
    else
    {
   
   
    }
    //date
    if( document.f1.dt1.value == "" )
   {
     document.getElementById("msg4").innerHTML="select Date";
     document.f1.dt1.focus() ;
     return false;
    }
//Radio Button   
     var radios = document.getElementsByName("g1");
    var formValid = false;

    var i = 0;
    while (!formValid && i < radios.length) {
        if (radios[i].checked) formValid = true;
        i++;       
    }

    if (!formValid)
    {
     document.getElementById("msg5").innerHTML="select Gender";
    return formValid;
    }
    //chackbox
     var radios1 = document.getElementsByName("c1[]");
    var formValid1 = false;

    var i1 = 0;
    while (!formValid1 && i1 < radios1.length) {
        if (radios1[i].checked) formValid1 = true;
        i1++;       
    }

    if (!formValid1)
    {
     document.getElementById("msg6").innerHTML="select Hobby";
    return formValid1;
    }
    //city
var e = document.getElementById("txtcity").value;

if(e==0) //for text use if(strUser1=="Select")
{
alert("select City");
}
   
    //end js
   
   
       

  
        return( true );
}


</script>


</head>

<body>
<form action="#" method="post" name="f1" onsubmit="return(validateform());">

<table border="1">
    <tr>
        <th>First Name</th>
        <td><input type="text" name="txtfname" /></td>
        <td><span id="msg1"></span></td>
    </tr>
   
    <tr>
        <th>Last Name</th>
        <td><input type="text" name="txtlname" /></td>
        <td><span id="msg2"></span></td>   
    </tr>
    <tr>
        <th>Email</th>
        <td><input type="text" name="txtename" /></td>
    </tr>
    <tr>
        <th>Password</th>
        <td><input id="txtpass1" type="password" name="txtpass" /></td>
       
   
    </tr>
    <tr>
        <th>Confirm Password</th>
        <td><input id="txtpass2" type="password" name="txtconpass" /></td>
        <td><span id="txtpass23"></span></td>
   
    </tr>
    <tr>
        <th>Date OF Birth</th>
        <td><input type="date" name="dt1"  /></td>
        <td><span id="msg4"></span></td>
   
    </tr>   
    <tr>
        <th>Gender</th>
        <td>
            <input type="radio" name="g1" value="male" />Male
            <input type="radio" name="g1" value="female" />Female
        </td>
        <td><span id="msg5"></span></td>
   
    </tr>
    <tr>
        <th>Hobby</th>
        <td><input type="checkbox" name="c1[]" value="cri" />Cricket
            <input type="checkbox" name="c1[]" value="read" />Read
        </td>
        <td><span id="msg6"></span></td>
    </tr>
    <tr>
        <th>City</th>
        <td><select name="txtcity" id="txtcity" onChange="validateform()">
                <option value="0">select</option>
                <option value="1">Kalol</option>
                <option value="2">Amedabad</option>
                <option value="3">Patan</option>
                <option value="4">Maheshana</option>           
                <option value="5">Baroda</option>
            </select>
        </td>
        <td><span id="msg7"></span></td>
    <tr>
    <tr>
        <td colspan="3" align="center"><input type="submit" name="add" value="ADD" onblur="validateform()" onclick="validateform()" /></td>
   
    </tr>   
   
</table>


</form>
<?php /*?>
    <?php
        include('connection.php');
       
        if(isset($_POST['add']))
        {       
        $fname=$_POST['txtfname'];
        $lname=$_POST['txtlname'];
        $txtename=$_POST['txtename'];
       
        $txtconpass=$_POST['txtconpass'];
        $dt=$_POST['dt'];
        $mo=$_POST['mo'];
        $yr=$_POST['yr'];
        $dtat1=$dt."/".$mo."/".$yr;
        echo $dtat1;
        $gender=$_POST['g1'];
        $hobby=implode(',',$_POST['c1']);
        $txtcity=$_POST['txtcity'];

        $sql=mysql_query("insert into task1 values('','$fname','$lname','$txtename','$txtconpass','$dtat1','$gender','$hobby','$txtcity')");               
        if(!$sql)
        {
        echo mysql_error();
        }
        else
        {
            echo "insert";
        }
}
    ?><?php */?>
</body>

</html>