After a long time, we came back with new tutorial for beginner. In this tutorial we are going to make one HTML form and will submit data using serialize method in PHP and JQuery. First of all we should know little difference between Ajax and JQuery. Because it will be easy to understand about the languages those we are going to use.
Ajax: - Ajax is used to load data into page background without refreshing the current page or whole page. Example: - Facebook tabs.
JQuery: - JQuery helps to Ajax to show data in useful format way. Using Ajax and JQuery simultaneously, we request for text, Html data, JSON response from the server using PHP Methods.
For using JQuery, we need to add JQuery in our PHP page.
Example: -
we can use ajax using two methods like: -
In success function(data) - data variable in function has query response.
Now, we are going to combine all code together.
Using this Ajax method Ajax data will be POST to given PHP page (php_pageurl.php) file. Here we can get form value and can store it into database. echo syntax will send your given response to Ajax response. this is the easiest method for storing data into database.
If you still facing any difficulty then feel free to contact us or query us.
Thanks, Happy Coding!
Ajax: - Ajax is used to load data into page background without refreshing the current page or whole page. Example: - Facebook tabs.
JQuery: - JQuery helps to Ajax to show data in useful format way. Using Ajax and JQuery simultaneously, we request for text, Html data, JSON response from the server using PHP Methods.
For using JQuery, we need to add JQuery in our PHP page.
Example: -
JQuery Syntax: -
Get value using syntax: -
Get form values using serialize syntax: -
Now Ajax Code that we are going to use for form submission: -
we can use ajax using two methods like: -
// Method 1 $.ajax({ type:"POST", url:"php_pageurl.php", data:data, success:function(data) { $("#response_div").html(data); } }); return false; // Method 2 $.post("php_pageurl.php",{ data:data },function(data){ $("#response_div").html(data); }); return false;In above code data variable have all variable values of our form and sending form data using PHP POST method.
In success function(data) - data variable in function has query response.
Now, we are going to combine all code together.
Using this Ajax method Ajax data will be POST to given PHP page (php_pageurl.php) file. Here we can get form value and can store it into database. echo syntax will send your given response to Ajax response. this is the easiest method for storing data into database.
prepare("INSERT INTO YOURTABLE_NAME (name, age) VALUES('$name','$age')"); if($insertingintodatabase->execution()) { echo "success"; } else{ echo "fail"; } } ?>In the above PHP code, Don't forget to include your database connectivity. we are inserting the value into database using SQL Injunction Query.
If you still facing any difficulty then feel free to contact us or query us.
Thanks, Happy Coding!
0 comments :
Post a Comment