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>

Thursday, 26 February 2015

How to Dropdownlist in Data select And Delete with Ajax


Select_ajax.php
============
<script>
function hi(str)
{
    if(window.XMLHttpRequest)
    {
   
        xml=new XMLHttpRequest();
       
    }
    xml.onreadystatechange=function()
    {
       
        if(xml.readyState == 4 && xml.status==200)
        {
            document.getElementById("msg").innerHTML=xml.responseText;
            }
        }
       
        xml.open("GET","select_ajax1.php?id="+str,true);
        xml.send();
}

</script>
<select name="sel" onChange="hi(this.value)">
<option>select</option>
<?php
mysql_connect("localhost","root","");
mysql_select_db("work");

$sql=mysql_query("select * from registration");
while($row=mysql_fetch_array($sql))
{
    echo "<option value=".$row[0].">".$row[1]."</option>" ;
}
 ?>


</select>
<span id="msg"></span>


=====

select_ajax1.php
========
<?php
$name=$_GET['id'];
echo $name;

mysql_connect("localhost","root","");
mysql_select_db("work");

$sql=mysql_query("delete from registration where id=$name");


?>
=========

How to chack data avilable or not with Ajax

ajax.php
=========
<html>

                <script>
               
                        function hello(str)
                        {
                           
                           
                            if(window.XMLHttpRequest)
                            {
                                xmlhttp = new XMLHttpRequest() ; 
                            }
                           
                           
                        xmlhttp.onreadystatechange=function()
                        {
                            if(xmlhttp.readyState==4 && xmlhttp.status==200)
                                {
                                   
                    document.getElementById("msg").innerHTML=xmlhttp.responseText;
                                   
                                }
                        }
                           
                           
                    xmlhttp.open("GET","1.php?id="+str,true);       
                    xmlhttp.send();       
                           
                        }
               
               
               
                </script>



            <input type="text" name="name" onBlur="hello(this.value)">

            <span id="msg"></span>

</html>
======
1.php
======


<?php
       
       
       
        $name=$_GET['id'];
       
        mysql_connect("localhost","root","");
        mysql_select_db("test");
       
        $qu=mysql_query("select * from login where user_name='$name'");
        $n=mysql_num_rows($qu);
       
        if($n==1)
        {
                echo "USERNAME IS NOT AVAILABLE";
        }
        else
        {
                echo "OK";
        }
       
      
?>

How to multiple image uploded

<?php
mysql_connect("localhost","root","");
mysql_select_db("demo");

if(isset($_FILES['files'])){
    $errors= array();
    foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
        $file_name = $key.$_FILES['files']['name'][$key];
       
        $file_size =$_FILES['files']['size'][$key];
        //$file_tmp =$_FILES['files']['tmp_name'][$key];
        $file_type=$_FILES['files']['type'][$key];   
        if($file_size > 2097152){
            $errors[]='File size must be less than 2 MB';
        }       
        $query="INSERT into upload_data1  VALUES('','$file_name'); ";
        $desired_dir="user_data";
        if(empty($errors)==true){
            if(is_dir($desired_dir)==false){
                mkdir("$desired_dir", 0700);        // Create directory if it does not exist
            }
            if(is_dir("$desired_dir/".$file_name)==false){
                move_uploaded_file("$desired_dir/".$file_name);
            }else{                                    // rename the file if another one exist
                $new_dir="$desired_dir/".$file_name.time();
                 rename($new_dir) ;               
            }
         mysql_query($query);           
        }else{
                print_r($errors);
        }
    }
    if(empty($error)){
        echo "Success";
    }
}
?>


<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" name="files[]" multiple/>
    <input type="submit"/>
</form>

Registration form display data and delete or update with login

 registration.php
==============

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" enctype="multipart/form-data" name="f1">
  <table width="200" border="1">
    <tr>
      <td colspan="2"><div align="center"><strong>Registration</strong></div></td>
    </tr>
    <tr>
      <td>Name</td>
      <td><input type="text" name="txtname"  /></td>
    </tr>
    <tr>
      <td>Address</td>
      <td><textarea name="txtaddres"></textarea></td>
    </tr>
    <tr>
      <td>Gender</td>
      <td><input type="radio"  name="r1" value="male"/>Male
              <input type="radio"  name="r1" value="female"/>female
      </td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input type="email" name="txtemail"  /></td>
    </tr>
    <tr>
      <td>Mobile</td>
      <td><input type="text" name="txtmobile" /></td>
    </tr>
    <tr>
      <td>Website</td>
      <td><input type="text" name="txtwebsite" /> </td>
    </tr>
    <tr>
      <td>Hobby</td>
      <td><input type="checkbox" name="c1[]" value="cricket" />cricket
      <input type="checkbox" name="c1[]" value="Read" />Read
      <input type="checkbox" name="c1[]" value="sleep" />Sleep
     
      </td>
    </tr>
    <tr>
      <td>Qulification</td>
      <td>
      <select name="qul[]" multiple="multiple">
       <option >Select</option>
      <option value="12th">12th</option>
            <option value="Bca">BCA</option>
                  <option value="Mca">MCA</option>
      </select>
     
      </td>
    </tr>
    <tr>
      <td>Photo</td>
      <td><input type="file" name="file" /></td>
    </tr>
    <tr>
      <td>User Name</td>
      <td><input type="text" name="txtuname" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input type="password" name="txtpass" /> </td>
    </tr>
    <tr>
      <td>City</td>
      <td><select name="city">
                   <option >Select</option>
               <option value="kalol">Kalol</option>
               <option value="amdavad">Amedabad</option>
               <option value="Kadi">Kadi</option>
               <option value="mahuva">Mahuva</option>
               <option value="rajkot">Rajkot</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>State</td>
      <td>
     
      <select name="state">
                    <option >Select</option>
               <option value="gujarat">Gujarat</option>
               <option value="up">UP</option>
               <option value="Rajasthan">Rajasthan</option>
               <option value="mp">MP</option>
               <option value="Bihar">Bihar</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>Country</td>
      <td>
      <select name="country">
        <option value="india">India</option>
        <option value="us">US</option>
      </select>
     
      </td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="btninsert" value="Registration" /></td>
    </tr>
  </table>

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

<?php

mysql_connect("localhost","root","");
mysql_select_db('work');

if(isset($_POST['btninsert']))
{
$txtname=$_POST['txtname'];
$txtaddres=$_POST['txtaddres'];
$r1=$_POST['r1'];
$txtemail=$_POST['txtemail'];
$txtmobile=$_POST['txtmobile'];
$txtwebsite=$_POST['txtwebsite'];
$h=implode(',',$_POST['c1']);
$qul=implode(',',$_POST['qul']);

//this is image uploade
$file=$_FILES['file']['name'];
$randno=rand(1,5000000);
$image=$randno.$file;
//$image=$file.$randno;

move_uploaded_file($_FILES['file']['tmp_name'],'img/'.$image);
//move_uploaded_file($_FILES['file'],'img/'.$image,['tmp_name']);
//this is end
$txtuname=$_POST['txtuname'];
$txtpass=$_POST['txtpass'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$qr=mysql_query("insert into registration values('','$txtname','$txtaddres','$r1','$txtemail',$txtmobile,'$txtwebsite','$h','$qul','$image','$txtuname','$txtpass','$city','$state','$country')");


if(!$qr)
{
echo mysql_error();
}
else
{
header('location:select.php');
}

}
?>
========

login.php
========
<?php 
session_start()
?>

<form name="f1" method="post">
<label>User<input type="text" name="txtuser"></label>
<label>password<input type="password" name="txtpass"></label>
<input type="submit" name="btnlogin">

</form>
<?php
if(isset($_POST['btnlogin']))
{
    if($_POST['txtuser']=="mitul" && $_POST['txtpass']=="mitul")
    {
    $_SESSION['hello']=$_POST['txtuser'];
    header("location:select.php");
   
    }
    else{
    echo "wong user name and password";
   
    }
    }
?>
========
logout.php
=========
<?php
session_start();
unset($_SESSION['hello']);
header("location:login.php");

?>
========
select.php

========
<?php
session_start();

?>
<a href="logout.php">Logout</a>
<?php
if(!isset($_SESSION['hello']))
{
 header("location:login.php");

}
echo "<h2 style=color:red;>ADMIN &nbsp;".$_SESSION['hello']."</h2>";
 ?>
<table border="1" style="width:1000px; height:150px;">
<tr>
<td>Name</td>
<td>Address</td>
<td>Gender</td>
<td>Email</td>
<td>Mobile</td>
<td>Website</td>
<td>Hobby</td>
<td>Qulification</td>
<td>Image</td>
<td>user name</td>
<td>Password</td>
<td>City</td>
<td>State</td>
<td>Country</td>
<td>Delete</td>
</tr>
<?php

mysql_connect("localhost","root","");
mysql_select_db('work');


$qr=mysql_query("select * from registration");

while($row=mysql_fetch_array($qr))
{
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['mobile']."</td>";
echo "<td>".$row['website']."</td>";
echo "<td>".$row['hobby']."</td>";
echo "<td>".$row['qulification']."</td>";
echo "<td><img src='img/".$row['images']."' height=100px; width=100px;></td>";
echo "<td>".$row['user_name']."</td>";
echo "<td>".$row['password']."</td>";
echo "<td>".$row['city']."</td>";
echo "<td>".$row['state']."</td>";
echo "<td>".$row['country']."</td>";
echo '<td><a href="delete.php?name='.$row['id'].'">Delete</a>&nbsp;&nbsp;&nbsp;<a href="update.php?name='.$row['id'].'">Update</a></td>';
echo "</tr>";
}

if(isset($_GET['msg']))
{



}


?>
======
delete.php


=======
<?php
session_start();
 ?>
<?php
mysql_connect("localhost","root","");
mysql_select_db('work');

$id=$_GET['name'];

$qr=mysql_query("delete  from registration where id=$id");

if(!$qr)
{
echo mysql_error();


}
else
{
header("location:select.php?msg='Delete'");
}

?>
=========
update.php


=========
<?php
session_start()


?>

<?php





            mysql_connect("localhost","root","");
            mysql_select_db('work');
           
           
            $id=$_GET['name'];
    if(isset($id))
    {

               

                $qu=mysql_query("select * from registration where id=$id");           
                while($row=mysql_fetch_array($qu))
                {
                        ?>
                            <form method="post" enctype="multipart/form-data" name="f1">
  <table width="200" border="1">
    <tr>
      <td colspan="2"><div align="center"><strong>Registration</strong></div></td>
    </tr>
    <tr>
      <td>Name</td>
      <td><input type="text" name="txtname" value="<?php echo $row[1];  ?>"  /></td>
    </tr>
    <tr>
      <td>Address</td>
      <td><textarea name="txtaddres" ><?php echo $row[2] ?></textarea></td>
    </tr>
    <tr>
      <td>Gender</td>
      <td>
      <?php if($row[3]=='male')
      {
      
   echo  
   "<input type='radio'  name='r1' value='male' checked />Male
              <input type='radio'  name='r1' value='female'/>female"; }
            if($row[3]=='female')
            {
            echo  "<input type='radio'  name='r1' value='male'  />Male
              <input type='radio'  name='r1' value='female' checked/>female"; }
           
           
           
            ?>
      </td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input type="email" name="txtemail"  value=<?php echo $row[4]; ?> /></td>
    </tr>
    <tr>
      <td>Mobile</td>
      <td><input type="text" name="txtmobile" value=<?php echo $row[5]; ?> /></td>
    </tr>
    <tr>
      <td>Website</td>
      <td><input type="text" name="txtwebsite" value=<?php echo $row[6]; ?> /> </td>
    </tr>
    <tr>
      <td>Hobby</td>
      <td>
      <?php
      $h=$row[7];
      $hob=explode(',',$h);
      ?>
     
      <input type="checkbox"  name="c1[]" value='cricket'
      <?php if(in_array('cricket',$hob)) { echo 'checked=checked'; } ?> />cricket
      <input type="checkbox"  name="c1[]" value="Read" <?php if(in_array('Read',$hob)){ echo 'checked=checked'; } ?> />Read
      <input type="checkbox" name="c1[]" value="sleep" <?php if(in_array('sleep',$hob)) { echo 'checked=checked'; } ?> />Sleep
     
      </td>
    </tr>
    <tr>
      <td>Qulification</td>
      <td>
      <?php
      $s=$row[8];
      $se=explode(',',$s);
     
     
        ?>
      <select name="qul[]" multiple="multiple">
       <option >Select</option>
      <option value="12th"  <?php if(in_array('12th',$se)) { echo 'selected=selected'; } ?>>12th</option>
            <option value="Bca" <?php if(in_array('Bca',$se)) { echo 'selected=selected';} ?>>BCA</option>
             <option value="Mca" <?php if(in_array('Mca',$se)) {echo 'selected=selected'; } ?> >MCA</option>
      </select>
     
      </td>
    </tr>
    <tr>
      <td>Photo</td>
      <td><input type="file" name="file" /></td>
    </tr>
    <tr>
      <td>User Name</td>
      <td><input type="text" name="txtuname"  value="<?php echo $row[11]; ?>"/></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input type="password" name="txtpass" value="<?php echo $row[12]; ?>" /> </td>
    </tr>
    <tr>
      <td>City</td>
      <td>
    
      <select name="city">
                   <option >Select</option>
               <option value="kalol"<?php if($row['city']=='kalol'){ echo 'selected=selected';} ?>>Kalol</option>
               <option value="amdavad" <?php if($row['city']=='amdavad') { echo 'selected=selected';} ?>>Amedabad</option>
               <option value="Kadi" <?php if($row['city']=='Kadi') { echo 'selected=selected'; } ?>>Kadi</option>
               <option value="mahuva" <?php if($row['city']=='mahuva') { echo 'selected=selected'; } ?>>Mahuva</option>
               <option value="rajkot" <?php if($row['city']=='rajkot') { echo 'selected=selected'; } ?>>Rajkot</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>State</td>
      <td>
     
      <select name="state">
                    <option >Select</option>
               <option value="gujarat" <?php if($row['state']=='gujarat') { echo 'selected=selected'; } ?>>Gujarat</option>
               <option value="up" <?php if($row['state']=='up') { echo 'selected=selected'; } ?>>UP</option>
               <option value="Rajasthan" <?php if($row['state']=='Rajasthan') { echo 'selected=selected'; } ?>>Rajasthan</option>
               <option value="mp" <?php if($row['state']=='mp') { echo 'selected=selected'; } ?>>MP</option>
               <option value="Bihar" <?php if($row['state']=='Bihar') { echo 'selected=selected'; } ?>>Bihar</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>Country</td>
      <td>
      <select name="country">
        <option value="india" <?php  if($row['country']=='india') { echo 'selected=selected'; } ?>>India</option>
        <option value="us" <?php if($row['country']=='us') { echo 'selected=selected'; } ?>>US</option>
      </select>
     
      </td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="sbt" value="Update" /></td>
    </tr>
  </table>

</form>

                        <!--   
                                    $txtadd=$row['address'];
               
                    echo "<form name=f1 method=post>";
                    echo "<input type='text' name='txtname' value=".$row['name']."> ";
                    //echo "<textarea name='txtaddres'>$txtadd</textarea>";
                    //echo "<input type='text' name='txtaddress' value=$txtadd>";
                    echo "<input type='text' name='txtaddress' value=".$row['address'].">";
                    echo "<input type='text' name='txtgender' value=".$row['gender'].">";
                    echo "<input type='text' name='txtemail' value=".$row['email'].">";
                    echo "<input type='text' name='txtmo' value=".$row['mobile'].">";
                    echo "<input type='text' name='txtwebsite' value=".$row['website'].">";
                    echo "<input type='text' name='txthobby' value=".$row['hobby'].">";       
                    echo "<input type='text' name='txtqul' value=".$row['qulification'].">";
                    echo "<input type='text' name='txtimg' value=".$row['images'].">";
                    echo "<input type='text' name='txtuname' value=".$row['user_name']." >";
                    echo "<input type='text' name='txtpass' value=".$row['password'].">";
                    echo "<input type='text' name='txtcity' value=".$row['city'].">";
                    echo "<input type='text' name='txtstate' value=".$row['state'].">";
                    echo "<input type='text' name='txtcountry' value=".$row['country'].">";
                    echo "<input type='submit' name='sbt'>";
echo '</form>';-->
               
                <?php } }?>


           
           
            <?php
           
            if(isset($_POST['sbt']))
            {
                $id=$_GET['name'];
                $name=$_POST['txtname'];
                $address=$_POST['txtaddres'];   
                $gender=$_POST['r1'];
                $email=$_POST['txtemail'];
                $mobile=$_POST['txtmobile'];
                $website=$_POST['txtwebsite'];
                $hobby=implode(",",$_POST['c1']);
                $qul=implode(",",$_POST['qul']);               
                $uname=$_POST['txtuname'];
                $pass=$_POST['txtpass'];
                $city=$_POST['city'];           
                $state=$_POST['state'];
                $country=$_POST['country'];
   
   
                        $file=$_FILES['file']['name'];
                if($file)
                {           
                $randno=rand(1,5000000);
                $image=$randno.$file;
                move_uploaded_file($_FILES['file']['tmp_name'],'img/'.$image);
                $qu=mysql_query("update registration set name='$name',address='$address',gender='$gender',email='$email',mobile='$mobile',website='$website',hobby='$hobby',qulification='$qul',images='$image',user_name='$uname',password='$pass',city='$city',state='$state',country='$country' where id=$id");
                if(!$qu)
                {
                        echo mysql_error();
                }
                else
                {
                   
                   
                    echo "IMAGES";
                    header("Location:select.php");
                   
                }   
            }       
        else
        {
                   
$qu=mysql_query("update registration set name='$name',address='$address',gender='$gender',email='$email',mobile='$mobile',website='$website',hobby='$hobby',qulification='$qul',user_name='$uname',password='$pass',city='$city',state='$state',country='$country' where id=$id");
                if(!$qu)
                {
                        echo mysql_error();
                }
                else
                {
                   
                header("Location:select.php");
                   
                   
                    echo "WITHOUT IMAGE";
                   
                }       
           
            }
            }
            //    $qu=mysql_query("update registration set name='Harish' where id=13");




?>