Basic PHP

Advanced PHP

Form Handling

You should have already learnt how to write an HTML form before. As a revision, let's take a look at the following HTML form:

<html>

<head>

<title>HTML Form</title>

</head>

<body>

<form action="ch03_01_login.php" method="get">

User Name: <input type="text" name="user" /><br>

Password: <input type="password" name="pwd" /><br>

<input type="submit" value="Login"/>

</form>

</body>

</html>

In this lesson, you will learn how to process the form data using PHP scripts.


Getting the Form Data

How to get the form data depends on the method used in submitting the HTML form:

For example, to get the submitted user name and password of the sample form, the following PHP code can be used:

$userName = $_GET['user'];

$password = $_GET['pwd'];

If you do not care about the method used in submitting the form data, you can also use the $_REQUEST array variable. The $_REQUEST variable is an associative array that contains the contents of $_GET, $_POST and $_COOKIE. (We will discuss cookies in later lesson.)

Go to the next step of this tutorial


<< Include File Next >>

Copyright © 2010. MyTutorialPlanet. All rights reserved.