I am trying to insert input values into database with the help of form without refreshing the page.For this my form is
<html>
<head>
<title>Jquery test</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$('insert').click(function() {
$.post("test2.php", $(this).closest("form").serialize());
});
</script>
</head>
<body>
<form id="test">
<table>
<tr>
<td>First Name</td>
<td><input type="text" name="fname"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname"></td>
</tr>
<tr>
<td colspan="2"><input type="button" name="insert" value="insert"></td>
</tr>
</table>
</form>
</body>
</html>
And my test2.php file is-
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
$sql="INSERT INTO user (first_name,last_name) VALUES ('".$_POST['fname']."','".$_POST['lname']."')";
mysql_query($sql);
?>
but this is not working for me.Please help me.Thank you in advance.