PHP Tutorial - How to read user inputs
1. $_GETLet see these variables in detail
2. $_POST
3. $_REQUEST
1. $_GET
It is used to read form elements if form method is set to "GET".
2. $_POST
It is used to read form elements if form method is "POST".
3. $_REQUEST
It is used to retrieve form elements irrespective of form method attribute. That is whether form method is GET or POST it will retrieve form elements. I will recommend using $_REQUEST for safe programming.
Example
First let us create an HTML page containing simple form elements.
Sample_form.html
<html>
<head>
<title>Sample html form</title>
</head>
<body>
<form name="form1" action="Sample_display.php">
Enter your name <input type="text" name="user">
<input type="submit" value="submit">
</form>
</body>
</html>
Create an PHP program to read user entered value .
Sample_display.php
<?
$user_name=$_REQUEST["user"];
//user is the text box name in Sample_form.html page. $user_name is an variable.
echo "Welcome ".$user_name;
?>
Output
Sample_form.html
Sample_display.php
Welcome John smith
On clicking the "Submit" button it will redirect to Sample_display.php and display the content entered in the text box.



Comments