Tue Jan 01, 2013 5:00 pm
<html>
<head>
<title>Post parameters using JQuery</title>
<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
Note you can download the JQuery package instead of using Google version. -->
<script src="jquery-1.8.3.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("JQuery.php",
{
name:"Dom adnos",
age:"43"
},
function(data,status){
$("div#div1").html("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
</head>
<body>
<button>Send POST and return status with DB content</button>
<div id="div1"></div>
</body>
</html>
<?php
if(isset($_POST['name'])){
$name=$_POST['name'];
}
if(isset($_POST['age'])){
$age=$_POST['age'];
}
$servername="localhost";
$dbuser="root";
$dbpassword="";
$dbname="JQuery";
$table="user";
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
$query ="insert into $table values('$name', $age ) ";
$result=mysql_query($query) ;
echo mysql_error();
echo "<br> Affected rows :".mysql_affected_rows();
//$date = date("Y-m-d H:i:s");
$query ="select * from $table ";
$result=mysql_query($query) ;
?>
<table border="1" >
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['name']."</td>" ;
echo "<td>".$row['age']."</td>" ;
echo "</tr>";
}
?>
</table>
--
-- Table structure for table `user`
--
CREATE TABLE IF NOT EXISTS `user` (
`name` varchar(50) NOT NULL DEFAULT '',
`age` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.