Insert data in Database Using Jquery

-Insert data in Database Using Jquery -Create a index.php and code.php file with code -database name 'school' -tabale Name 'class' -thene Working it code File Name :- index.php

<html>
<head>
<title></title>
<script type="text/javascript" src="jquery.js"></script>  //Install Jquery
<script type="text/javascript">
$('document').ready(function(){
$('#button').click(function(){
if($('#fname').val()==""){
alert("Enter first name");
return false;
} else
{
var fname = $('#fname').val();
}
if($('#passwd').val()==""){
alert("Enter Password");
return false;
}else
{
var password = $('#passwd').val();
}
jQuery.post("code.php", {
firstname:fname,
pass: password
},  function(data, textStatus){
if(data == 1){
$('#response').html("Registration successfull!!");
$('#response').css('color','green');
}else{
$('#response').html("Some Error Occurred");
$('#response').css('color','red');
}
});
});
});
</script>
</head>
<body>
<div id="form">
<form>
<label>Name :</label>
<input type="text" id="fname" />
<br />
<br />
<label>Password :</label>
<input type="password" id="passwd" />
<br /><br/>
<input type="button" id="button" value="Insert" /><br />
<label id="response"></label>
</form>
</div>
</body>
</html>

  Create Filename :- code.php

<?php
$connection = mysql_connect('localhost', 'root', '')  or die("Opps some thing went wrong");  //connection establis hear
$db = mysql_select_db('school', $connection) or die("Opps some thing went wrong");
$name = $_POST['firstname'];
$password = $_POST['pass'];
$encrypted = md5($password); // Encrypting pssword using md5 algo
$query=mysql_query("INSERT INTO class(`name`,`password`) VALUES('$name','$encrypted')");  //insert data in database
if(mysql_affected_rows()>0){
echo "1";
}else{
echo "2";
}
?>