Php form is a document that contain blank fields, that the user can fill the date or user can select the data. This data will be collected by 'get' or 'post' method and stored in the database. Php form is simply HTML form with no special tag.
SYNTAX OF PHP FORM
<form action = " " method = " " >
</form >
Example :-
text.php
The above example containing a simple HTML form with two input fields and one text area for comment and a submit button to collect the filled form data. To collect form data HTTP POST method is used you can also use HTTP GET method to collect the form data. Write the above code in notepad and save it as text.php.
This form data is collected on data.php which look likes this
data.php
For the real programming scenario don't perform the echo function. Here echo function is performed to show you how the code is working.
Output of the above code
The above complete example shows the collection of form date in different page but you can also collect the form date in the same page. See the below example how to collect the form data in the same page. For this we only need to write the data.php code in the same page that in on the text.php.
And to collect the form data php inbuilt function 'isset' is used. And making the form action attribute empty.
Example 2:-
text.php
Difference between 'GET METHOD' and 'POST METHOD' :-
GET METHOD :-
1. GET Method is visible to everyone. It will be displayed in the browsers address bar.
2. GET Method is has limits on the amount of information send.
3. GET is less secure compared to POST because data sent is part of the URL. So it's saved in browser history and server logs in plain text.
POST MTHOD :-
1. POST Method variables are not displayed in the URL.
2. POST Method has no limitation.
3. POST is a little safer than GET because the parameters are not stored in browser history or in web server logs.
No comments:
Post a Comment