PHP tutorial: Query string

PHP tutorial: Query string


Query string

The information can be sent across the web pages. This information is called query string. This query string can be passed from one page to another by appending it to the address of the page. You can pass more than one query string by inserting the & sign between the query strings. A query string can contain two things: the query string ID and its value. The query string passed across the web pages is stored in $_REQUEST, $_GET, or $_POST variable. Whether you passed the query string by using GET or POST method, it is stored in $_REQUEST variable. If you want to access the query string you can use these variables. You should note that whether the query string is passed by the GET or POST method it can be accessed by using the $_REQUEST variable. If you want to use $_GET variable to access the query string the form method need to be GET. Also you can use $_POST variable to get the query string if the form method is POST.

In the following example, the query strings username and email(the names of texboxes) are passed from a page called login.php to another page called welcome.php when you click the submit button.



Login.php:
<html>
<head>
<title>Login form</title>
</head>
<body>
<form action="welcome.php" method=”get”>
<table>
<tr>
<td>User name:</td><td> <input type="text" name="username" ></td>
</tr>
<tr>
<td>E-mail: </td><td><input type="text" name="email" ></td>
</tr>
<tr>
<td><input type="submit" name="sub" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>

welcome.php:
<?php
echo "<strong>Welcome ".$_GET['username']. "!</strong><br/>";
echo "Please remember this e-mail: ".$_GET['email']. " for later use.";
?>



Comments

zdzsfdsfxdfdgdf comment

 zdzsfdsfxdfdgdf

zfcsdvdfscsdvdfv


2018-02-28
fff comment

 fff

fffd


2017-01-28




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.