you must have two files ..
index.html
savedata.php
now you can send Form Data from index.html to savadata.php via jQuery , AJAX .
Just Follow these steps .
Add this Script into your index.html which have already created .
<script>
jQuery(function(){
$('form').submit(function(e) {
e.preventDefault();
var username = $("#userName").val();
var password = $("#password").val();
var cPassword = $("#passwordConfirm").val();
// i am validating confirm password on client side but don't do it for security reasons
if(password == cPassword) {
// now send the Form Data to Server Side to save theme
$.post('savadata.php', {
username:username,
password:password
} , function(responce){
if(responce == '1') {
// form submitted successfully
// clear form fields
$("#userName").val('');
$("#password").val('');
$("#passwordConfirm").val('');
alert('Data Saved...');
} else {
alert('there is an error to save data');
}
})
} else {
alert('Confirm password not matched');
}
}
});
</script>
and the savedata.php
will recive the Data in $_POST
array
you can treat theme like this .
<?php
$username = $_POST['username'];
$password = md5($_POST['password']);
// Do what ever you want with savadata.php
// if Data Saved Successfuly echo '1'; javascript will take this flag as your data is saved.
?>