Thursday 9 April 2015

Submitting and Retrieving Forms data using PHP

Web forms are GUI element wherein the data to be processed is submitted to the web server. The whole process is called client/server data processing model. It is applicable in web sites and web applications. Web form contains text boxes, buttons, check boxes, which allows the user to enter the required information. Web form contains a submit button, when you clicked the submit button, the contents of the form is submitted to the server for processing.
Form is formed using <form> tag which having attributes like action, method, enctype and name. All attributes having their own functions, for example enctype is used for making encryption for form contents.

Submitting the form data

The data of the form cab be sent to the server using either the post() or get() method. The get() method having  attribute method equal to get() and post method having attribute method equal to post().
For example : <form name ="amar" method ="get" action="amar.php">.
Note : In post method information submitted by the user don't show whereas in get information entered by the user Shows in url.

Retrieving Form data

The form data retrieve using php file(amar.php. You must have a web server like apache or wampserver and the both HTML and PHP files should be in same directory(root directory) of the server. The server is used for transmitting data and retrieving data. Lei's see how we can do it.
First make a form in HTML file.
<html>
<head>
<title>Data transmission</title>
</head>
<body>
<form name="amar" method="get" action="amar.php">
First name:
<input type="text" name="first" />
</br>
Last name:
<input type="text" name="last" />
</br>
<input type="submit" value="submit" name="button">
</body>
</html>

 

Now retrieve data using these lines.

<html>
<head>
<title>retrieving data</title>
</head>
<body>
first name is :
<?php
echo $_GET["first"];
?>
</br>
last name is :
<?php
echo $_GET["last"];
?>
</body>
</html>


It's all about HTML and PHP form data transmission.In next article we will focus on Database connection using PHP.

 

1 comment: