//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
include("connect.php");
$query=mysql_query("select * from `student`");
?>
<html>
<head>
<script src="jquery-1.10.1.js"></script>
<script language="javascript">
function g(e,f)
{
if(f=='delete.php') { confirmation=confirm('You want to delete your own account???'); if(confirmation==false) return; }
document.getElementById('mydatatobesent').value=e;
document.getElementById('myform').action=f;
document.getElementById('myform').submit();
}
function h(v1,v2)
{
v3=v1+v2;
n=document.getElementById(v3).innerHTML;
c=document.createElement("input");
c.setAttribute("type","text");
c.setAttribute("value",n);
c.setAttribute("id",v3);
mm="vv("+v1+",'"+v2+"')";
c.setAttribute("onBlur",mm);
document.getElementById(v3).parentNode.replaceChild(c,document.getElementById(v3));
}
function vv(v1,v2)
{
v3=v1+v2;
n=document.getElementById(v3).value;
$.ajax( {
url: 'change.php',
type: 'POST',
data: {"id":v1,"field":v2,"textentry":n},
success: function(datareturned) {
console.log(datareturned);
}
});
c=document.createElement("div");
c.innerHTML=n;
c.setAttribute("id",v3);
mm="h("+v1+",'"+v2+"')";
c.setAttribute("onClick",mm);
//c.setAttribute("onClick","h(v1,v2)");
document.getElementById(v3).parentNode.replaceChild(c,document.getElementById(v3));
}
</script>
</head>
<body bgcolor="#00FF00">
<table border="3" bgcolor="#CCFFFF" style="position:absolute; top:20%">
<tr bgcolor="#CCFF00">
<th>NAME</th>
<th>AGE</th>
<th>PHONE</th>
<th>ADDRESS</th>
<th>DELETE</th>
</tr>
<form id="myform" method="post">
<input type="hidden" name="id" id="mydatatobesent" value="gg"/>
</form>
<?php
while($row=mysql_fetch_array($query))
{
$r=$row['id'];
?>
<tr>
<script language="javascript">
</script>
<td>
<div onClick="h(<?php echo $r; ?>,'NAME')" id="<?php echo $r."NAME"; ?>">
<?php
echo $row['NAME'];
?>
</div>
</td>
<td>
<div onClick="h(<?php echo $r; ?>,'AGE')" id="<?php echo $r."AGE"; ?>">
<?php
echo $row['AGE'];
?>
</div>
</td>
<td>
<div onClick="h(<?php echo $r; ?>,'PHONE')" id="<?php echo $r."PHONE"; ?>">
<?php
echo $row['PHONE'];
?>
</div>
</td>
<td>
<div onClick="h(<?php echo $r; ?>,'ADDRESS')" id="<?php echo $r."ADDRESS"; ?>">
<?php
echo $row['ADDRESS'];
?>
</div>
</td>
<td>
<?php
echo "<button onclick=\"g($r,'delete.php')\" <strong>DELETE</strong> </button> ";;
//return confirm('You want to delete your own account???');
?>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// change.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
include("connect.php");
$id=$_POST['id'];
$field=$_POST['field'];
$textentry=$_POST['textentry'];
//echo "update student set $field = $textentry where id='$id'";
mysql_query("update `student` set `$field` = '$textentry' where `id`='$id'") or die(mysql_error());
?>
//// End change.php
///////////////////////////////////////////////////////////////////////////////////////////////////
No comments:
Post a Comment