Insert page code:
<?php
try
{
$cn=mysql_connect('localhost','root','') or die('Error on connetion:'.mysql_error());
$db=mysql_select_db('sankar') or die('Error on database:'.mysql_error());
$id =json_encode($_POST['id']);
$name1 =json_encode( $_POST['ab']);
$age = json_encode($_POST['age']);
$cm=mysql_query("insert into emp values($id,$name1,$age)");
$ds=mysql_query("select * from emp order by eid");
while($dt=mysql_fetch_array($ds))
{
$arr[]=array
(
'ID'=>$dt[0],
'NAME'=>$dt[1],
'AGE'=>$dt[2]
);
}
echo json_encode($arr);
mysql_close($cn);
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?>
view page code:
<!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>
<script language="javascript" type="text/javascript" src="jquery-1.7.1.js"></script>
<script language="javascript" type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#c').on('click', function () {
var id= $('#a').val();
var ab=$('#b').val();
var age= $('#g').val();
$.ajax({
url: "f.php",
type: "POST",
data:{id:id,ab:ab,age:age},
cache: false,
datatype: "json",
success: function (data) {
data= eval(data);
$('#dv').html('');
var table = '<table border="1" cellpadding="0" cellspacing="0" >';
table += '<tr><td>User Id</td><td>User Name</td><td>User Age</td></tr>';
for(var i=0;i<data.length;i++)
{
table +='</tr>';
table +='<td>'+ data[i].ID + '</td>';
table +='<td>'+ data[i].NAME + '</td>';
table +='<td>'+ data[i].AGE + '</td>';
table +='</tr>';
}
table +='</table>';
$('#dv').html(table);
}
});
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="frm" id="frm" action="#" method="post" enctype="multipart/form-data">
<table align="center" cellpadding="0" cellspacing="0">
<tr><td>EID</td><td><input type="text" name="a" id="a" size="15" maxlength="10" /></td></tr>
<tr><td>Name</td><td><input type="text" name="b" id="b" size="30" maxlength="50" /></td></tr>
<tr><td>Age</td><td><input type="text" name="g" id="g" size="30" maxlength="50" /></td></tr>
<tr><td> </td><td><input type="button" name="c" id="c" value="Save" style="width:80px" /></td></tr>
<tr><td> </td><td><div id="dv"></div></td></tr>
</table>
</form>
</body>
</html>
<?php
try
{
$cn=mysql_connect('localhost','root','') or die('Error on connetion:'.mysql_error());
$db=mysql_select_db('sankar') or die('Error on database:'.mysql_error());
$id =json_encode($_POST['id']);
$name1 =json_encode( $_POST['ab']);
$age = json_encode($_POST['age']);
$cm=mysql_query("insert into emp values($id,$name1,$age)");
$ds=mysql_query("select * from emp order by eid");
while($dt=mysql_fetch_array($ds))
{
$arr[]=array
(
'ID'=>$dt[0],
'NAME'=>$dt[1],
'AGE'=>$dt[2]
);
}
echo json_encode($arr);
mysql_close($cn);
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?>
view page code:
<!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>
<script language="javascript" type="text/javascript" src="jquery-1.7.1.js"></script>
<script language="javascript" type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#c').on('click', function () {
var id= $('#a').val();
var ab=$('#b').val();
var age= $('#g').val();
$.ajax({
url: "f.php",
type: "POST",
data:{id:id,ab:ab,age:age},
cache: false,
datatype: "json",
success: function (data) {
data= eval(data);
$('#dv').html('');
var table = '<table border="1" cellpadding="0" cellspacing="0" >';
table += '<tr><td>User Id</td><td>User Name</td><td>User Age</td></tr>';
for(var i=0;i<data.length;i++)
{
table +='</tr>';
table +='<td>'+ data[i].ID + '</td>';
table +='<td>'+ data[i].NAME + '</td>';
table +='<td>'+ data[i].AGE + '</td>';
table +='</tr>';
}
table +='</table>';
$('#dv').html(table);
}
});
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="frm" id="frm" action="#" method="post" enctype="multipart/form-data">
<table align="center" cellpadding="0" cellspacing="0">
<tr><td>EID</td><td><input type="text" name="a" id="a" size="15" maxlength="10" /></td></tr>
<tr><td>Name</td><td><input type="text" name="b" id="b" size="30" maxlength="50" /></td></tr>
<tr><td>Age</td><td><input type="text" name="g" id="g" size="30" maxlength="50" /></td></tr>
<tr><td> </td><td><input type="button" name="c" id="c" value="Save" style="width:80px" /></td></tr>
<tr><td> </td><td><div id="dv"></div></td></tr>
</table>
</form>
</body>
</html>
No comments:
Post a Comment