Query string is usual part of any website it sits in the URL bar and associated with website URL for navigation to the different sections of the website. use of query string to send data of one page to others.
Example of query string;
index.php?page=user&role=admin
The query string always starts with Question mark (?) and separates two variables with address operator(&).
Example program of Query string :-
page page1.php
<?php
if ( isset ( $_POST['submit'] ) )
{
$url = "nextpage.php?fname=".$_POST['fname']."&lname=".$_POST['lname']."&fdigit=".$_POST['fdigit']."&sdigit=".$_POST['sdigit'];
header("Location:$url");
}
?>
<html>
<head><title>PHP Query String.</title></head>
<body>
<center>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<table cellpadding="0" cellspacing="0">
<tr><td>Firt name</td><td><input type="text" name="fname" /></td></tr>
<tr><td>Last name</td><td><input type="text" name="lname" /></td></tr>
<tr><td>First digit</td><td><input type="text" name="fdigit" /></td></tr>
<tr><td>Second digit</td><td><input type="text" name="sdigit" /></td></tr>
<tr><td> </td><td><input type="submit" name="submit" value="Go.." /></td></tr>
</table>
</form>
</center>
</body>
</html>
This program contains nothing the whole magic at the nextpage.php
Page nextpage.php
<html>
<head><title>Next page</title></head>
<body>
<center>
<table cellpadding="0" cellspacing="0">
<tr><td>Firt name</td><td><?php echo $_GET['fname'];?></tr>
<tr><td>Last name</td><td><?php echo $_GET['lname'];?></td></tr>
<tr><td>First digit</td><td><?php echo $_GET['fdigit'];?></td></tr>
<tr><td>Last digit</td><td><?php echo $_GET['sdigit'];?></td></tr>
<?php
$sum = $_GET['fdigit']+$_GET['sdigit'];
?>
<tr><td>Sum:</td><td><?php if ( isset ( $sum ) ) echo $sum; ?></td></tr>
</table>
</center>
</body>
</html>
There are two option to get value from a query string $_GET and $_REQUEST these both are PHP globals array.
The major drawback with Query string that they can be manipulate while running.
TIP :- NEVER SEND SENSITIVE DATA USING QUERY STRING BECAUSE ITS SHOWS WHAT IS CONTAINS.
Example of query string;
index.php?page=user&role=admin
The query string always starts with Question mark (?) and separates two variables with address operator(&).
Example program of Query string :-
page page1.php
<?php
if ( isset ( $_POST['submit'] ) )
{
$url = "nextpage.php?fname=".$_POST['fname']."&lname=".$_POST['lname']."&fdigit=".$_POST['fdigit']."&sdigit=".$_POST['sdigit'];
header("Location:$url");
}
?>
<html>
<head><title>PHP Query String.</title></head>
<body>
<center>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<table cellpadding="0" cellspacing="0">
<tr><td>Firt name</td><td><input type="text" name="fname" /></td></tr>
<tr><td>Last name</td><td><input type="text" name="lname" /></td></tr>
<tr><td>First digit</td><td><input type="text" name="fdigit" /></td></tr>
<tr><td>Second digit</td><td><input type="text" name="sdigit" /></td></tr>
<tr><td> </td><td><input type="submit" name="submit" value="Go.." /></td></tr>
</table>
</form>
</center>
</body>
</html>
This program contains nothing the whole magic at the nextpage.php
Page nextpage.php
<html>
<head><title>Next page</title></head>
<body>
<center>
<table cellpadding="0" cellspacing="0">
<tr><td>Firt name</td><td><?php echo $_GET['fname'];?></tr>
<tr><td>Last name</td><td><?php echo $_GET['lname'];?></td></tr>
<tr><td>First digit</td><td><?php echo $_GET['fdigit'];?></td></tr>
<tr><td>Last digit</td><td><?php echo $_GET['sdigit'];?></td></tr>
<?php
$sum = $_GET['fdigit']+$_GET['sdigit'];
?>
<tr><td>Sum:</td><td><?php if ( isset ( $sum ) ) echo $sum; ?></td></tr>
</table>
</center>
</body>
</html>
There are two option to get value from a query string $_GET and $_REQUEST these both are PHP globals array.
The major drawback with Query string that they can be manipulate while running.
TIP :- NEVER SEND SENSITIVE DATA USING QUERY STRING BECAUSE ITS SHOWS WHAT IS CONTAINS.
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI want a Simple query string's programs
ReplyDeleteGood 1!
ReplyDeleteRavi, I recently had the good fortune of reading this article regarding Header, Url & Location. It is well-written and contained sound, practical advice. In fact, I have already benefited from your discussion on.
ReplyDeleteEdit My College Research Paper Online
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteDot Net Training in Chennai | Asp.Net Training in Chennai
Selenium Training in chennai | Selenium Coaching Institute in Chennai
Software Testing Training Institute in Chennai | Testing Courses in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Course in Chennai | PHP Training Institute in Chennai