Copy Code code as follows:
<script type= "Text/javascript" >
$ (document). Ready (function ()
{
$ ('. Edit_link '). Click (Function ()
{
$ ('. Text_wrapper '). Hide ();
var data=$ ('. Text_wrapper '). html ();
$ ('. Edit '). Show ();
$ ('. EditBox '). HTML (data);
$ ('. EditBox '). focus ();
});
$ (". EditBox"). MouseUp (function ()
{
return False
});
$ (". EditBox"). Change (function ()
{
$ ('. Edit '). Hide ();
var boxval = $ (". EditBox"). Val ();
var datastring = ' data= ' + boxval;
$.ajax ({
Type: "POST",
URL: "update_profile_ajax.php",
Data:datastring,
Cache:false,
Success:function (HTML)
{
$ ('. Text_wrapper '). HTML (boxval);
$ ('. Text_wrapper '). Show ();
}
});
});
$ (document). MouseUp (function ()
{
$ ('. Edit '). Hide ();
$ ('. Text_wrapper '). Show ();
});
});
</script>
<style type= "Text/css" >
Body
{
Font-family:arial, Helvetica, Sans-serif;
font-size:12px;
}
. Mainbox
{
width:250px;
margin:50px;
}
. text_wrapper
{
Border:solid 1px #0099CC;
padding:5px;
width:187px;
}
. edit_link
{
Float:right
}
. editbox
{
Overflow:hidden; Height:61px;border:solid 1px #0099CC; width:190px; Font-size:12px;font-family:arial, Helvetica, Sans-serif; padding:5px
}
</style>
<div class= "Mainbox" >
<a href= "#" class= "Edit_link" title= "edit" >Edit</a>
<?php
Include ("db.php");
$sql =mysql_query ("Select email from users where user_id= ' 1 '");
$row =mysql_fetch_array ($sql);
$profile = $row [' email '];
?>
<div class= "Text_wrapper" style= "><?php echo $profile;?></div>
<div class= "edit" style= "Display:none" ><textarea class= "EditBox" cols= "" rows= "3" name= "Profile_box" > </textarea></div>
</div>
update_profile_ajax.php
Copy Code code as follows:
<?php
if ($_post[' data '])
{
$data =$_post[' data '];
$data = mysql_escape_string ($data);
$sql = "Update users set email= ' $data ' where user_id= ' 1 '";
mysql_query ($sql);
}
?>