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>

No comments:

Post a Comment