I made a simple script to insert data to database using ajax and jquery . It seems that I am not receiving back any response , and I don't think I am doing something wrong . So , can anybody take a look and help me ?
process.php
<?php
$id = $_POST['id'];
$user= $_POST['username'];
$password = $_POST['password'];
$con = mysqli_connect('localhost','root','','car_rental');
$query = 'insert into car_admin (admin_id,admin_username,admin_password) values(?,?,?)';
$query = $con->prepare($query);
$query-> bind_param('iss',$id,$user,$password);
if($query->execute()) { echo "done";}
else { echo "failed"; }
$query->close();
$con->close();
?>
register.php
<script src="jquery-1.12.4.js"></script>
<script src="script.js"></script>
<form id="register" method="POST" >
<fieldset>
<legend>
Register
</legend>
ID: <input id="id" type="text" name="id" value="" />
Username : <input id="username" type="text" name="username" value="" />
Passsword : <input id="password" type="password" name="password" value="" />
<input id="submit" type="submit" name="submit" value="Register" />
</fieldset>
</form>
<div id="result"></div>
jquery
$(document).ready( function() {
$('#submit').click(function() {
var id = $('#id').val();
var username = $('#username').val();
var password = $('#password').val();
$.ajax({
type:'post',
url:'process.php',
data:'id='+id+'username='+username+'password='+password,
success:function(data){
$('#result').html(data);
}
});
});