Query string is a small amount of data and URL address followed by “?” symbol along with form data if you want to transfer some extra information from browser to server we can go for query string, to query string we can pass in two ways.
1. Query string with name and value
2. Query string only with value
By using $REQUEST we can read query string which is combination of name and value.
$_Get is used to read data from URL address.
$_POST is used to read data from body of document.
If we put the information using query string we can use $_Get to read URL address.
- <form method=”POST” action=”page1.php?
Sno=100 & city=hyd”>
<input name=’text1′><br>
<input name=’txt2′><br>
<input type=”submit” name =”sub” value=”click”>
</form>
page1.php
<?php
echo “Welcome”;
echo $_REQUEST[‘Sno’];
echo $_REQUEST[‘city’];
?> - <a href=”page1_php? s=sunset.jpg”>
<img src=”sunset.jpg” width=”1==”> </a>
<a href=”page1.php? qs=winter.jpg”>
<img src=”winter.jpg” width=”100″> </a>
Srever side scripts
<?php
$img=$_REQUEST[qs];
echo “<img src=$img width=600>”;?>
–> Not to disappear the given input
<?php
if(isset($_POST[‘sub’]))
{
$t1=$_POST[‘txt1’];
$t2=$_POST[txt2′];
echo “Value is $t1”;
echo “Value is $t2”;
echo $_POST[‘sub’];
}?>
<form method=”POST” action=”page1.php”>
<input name=”txt1″ value=”<?php echo $t1″?>>
<input name=”txt2″ value=”<?php echo $_POST[‘txt2’]”?>>
<input type= “submit” name= “sub” value=”click”>
</form>