Click here to Skip to main content
15,882,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, is there any way to auto add query strings to another page?

here's example,

on page1.php i have this code :

PHP
<?php

$id = $_GET['id'] && $name = $_GET['name'];

?>

so every time if i add $name query string so it will be add automatically on page2.php as text only or links etc.

Thanks
Posted

1 solution

If I understand you correctly, let's construct 2 web pages:
index.html
XML
<html>
<body>
<form action="newpage.php" method="get">
id: <input type="text" name="id" value="">
Name: <input type="text" name="name" value="">
<input type="submit" value="Submit">
</form>
</body>
</html>

newpage.php
<?php
if (isset($_GET)){

echo "display id as text ".$_GET['id']."<br>";
echo "display name as text ".$_GET['name']."<br>";
echo "display id as link <a href='#'>".$_GET['id']."</a><br>";
echo "display name as link <a href='#'>".$_GET['name']."</a><br>";
}

?>

Launch the index.html on your browser, type something into the id (say 123) and name (say sam) textboxes, press submit, the inputs will be sent via query string to the newpage.php as indicated in the action attribute of the form tag on index.html. The newpage.php will be display with the inputs, note the inputs appearing as query string (?id=123&name=sam) trailing the url on the address bar.
 
Share this answer
 
Comments
Member 10749093 22-Jan-15 1:04am    
this is like post and get Peter, but what i mean is like, for example, while page2.php is loading, check page1.php if there's 2 or more query strings then display them on page2.php . also, it must display query strings for id 123 only
Peter Leow 22-Jan-15 1:26am    
// You can find out the number of parameter that pass to a page using count()
if (count($_GET) >= 2){
// then loop thru the parameters in the querystring
foreach ($_GET as $key => $value) {
echo $key."=>".$value;
}
}
Member 10749093 22-Jan-15 1:34am    
if i add this on page2.php then how it will display that query strings "id" and "name" from page1.php ?
Peter Leow 22-Jan-15 2:09am    
So you launch the page2.php first, and during the loading expect it to check on page1.php for any query string. No, that will not work, because the $_GET is empty.
Member 10749093 22-Jan-15 11:01am    
so there is no other way to do that? by adding this link somesite.com/index.php?id=111111&name=sam on body or anything ? i need the only way to get query strings nothing else

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900