index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="jquery-3.1.0.min.js" type="text/javascript"></script>
<script src="myValidations.js" type="text/javascript"></script>
</head>
<body>
Username : <input type="text" id="txtusername"></>
Password : <input type="text" id="txtpassword"></>
<input type ="submit" value="Save" id="btnSave"></>
<div id="disp"></div>
</body>
</html>
myValidation.js
$(document).ready(function(){
$("#btnSave").click(function() {
var username = $("#txtusername").val();
var password = $("#txtpassword").val();
$.ajax({
type: 'POST',
url: 'savecontacts.php',
data: {user:username, pass:password},
success: function (data) {
alert(data);
}
});
});
});
savecontacts.php
<?php
require_once './connectDB.php';
$user = $_POST("user");
$pass = $_POST("pass");
mysqli_query($conn, "insert into tbluser (username, password) values ('$user','$pass')");
echo "Done!";
?>
My problem is - it's not working. It does not execute the php function. Does anybody have an idea about this? I'm new on this type of programming. I'm a desktop developer and now I'm practising web programming.
Thanks