chinmay.sahoo
New member
The code for hiUser.php expects to be run from whatsName.html. The form that called the hiUser.php code is expected to have an element called userName. Take a look at the code for hiUser.php and see what I mean.
Like many PHP pages, hiUser.php is mainly HTML. The only thing that’s different is the two new lines of code. One creates a variable called $userName, and the other uses that variable in a print statement.
The first line extracts the user name from the previous form. When the form is sent to the server, all the form data is passed to the server, which can extract the data. The filter_input() function is one way to retrieve that data.
When you call filter_input(), you need at least two parameters. The first indicates where PHP should look for the data. INPUT_GET is a predefined value, meaning the data was sent through the GET mechanism. (Of course, you can also use INPUT_POST if that’s how the data was sent.) he second parameter is the name of the value. It corresponds to the name attribute in the previous form. In this case, the form had one input element named “userName.” The value of that text field is now extracted and stored into a PHP variable named $userName. Almost all PHP and HTML interactions work this way; you build an HTML form with a bunch of input elements, and write PHP code to extract those elements into variables.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hi User</title>
</head>
<body>
<h1>Hi User</h1>
<h3>PHP program that receives a value from "whatsName"</h3>
<?php
$userName = filter_input(INPUT_GET, "userName");
print "<h3>Hi there, $userName!</h3>";
?>
</body>
</html>
Like many PHP pages, hiUser.php is mainly HTML. The only thing that’s different is the two new lines of code. One creates a variable called $userName, and the other uses that variable in a print statement.
The first line extracts the user name from the previous form. When the form is sent to the server, all the form data is passed to the server, which can extract the data. The filter_input() function is one way to retrieve that data.
When you call filter_input(), you need at least two parameters. The first indicates where PHP should look for the data. INPUT_GET is a predefined value, meaning the data was sent through the GET mechanism. (Of course, you can also use INPUT_POST if that’s how the data was sent.) he second parameter is the name of the value. It corresponds to the name attribute in the previous form. In this case, the form had one input element named “userName.” The value of that text field is now extracted and stored into a PHP variable named $userName. Almost all PHP and HTML interactions work this way; you build an HTML form with a bunch of input elements, and write PHP code to extract those elements into variables.