Click here to Skip to main content
14,979,508 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.
   
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
Peter Leow 22-Jan-15 11:28am
   
I think I am getting more confuse. Let's start from the beginning and try to break down the problem bit by bit.
1. I understand that there are 2 pages e.g. page1.php and page2.php. Right?
2. What do you have on the page1.php? (show some code)
3. What do you have on the page2.php? (show some code)
4. Which page do you want to launch on the browser first? page1.php or page2.php?
5. When that page in point 4 (say page1.php) is loading, you want it to read and display some content from the other page (say page2.php)? Am I understand it correctly?
You may want to elaborate your question based on this five points.
Member 10749093 22-Jan-15 11:58am
   
Thanks for your time helping me Peter.

1. yes, i have 2 pages. page1.php and page2.php
2. on page1.php i have this code

if(isset($_GET["id"]) && trim($_GET["id"]) == '1111' && isset($_GET["name"]) && trim($_GET["name"]) == 'sam' ){
echo 'Your name is Sam';
}
else{
echo 'Your name is Not Sam';
}

if(isset($_GET["id"]) && trim($_GET["id"]) == '1111' && isset($_GET["name"]) && trim($_GET["name"]) == 'jake' ){
echo 'Your name is jake';
}
else{
echo 'Your name is Not jake';
}

see there's 2 query strings with name sam and jake, that 2 names i want them to be displayed on page2.php .

3. i don't have code on page2.php to make it display that 2 names "this is what i need".
4. i launch page2.php first on browser.
5. no, not page1.php . i want page2.php when it's loading, i want it to read and display that 2 names sam and jake that i put them as query string that is in page1.php .
Peter Leow 22-Jan-15 22:23pm
   
As page1.php is a server-side script, it will be executed on the server whenever you try to access its content and it will only return you the html output which will be stripped off all the php code such as the $_GET. So the answer is no.
Member 10749093 23-Jan-15 10:10am
   
ok thanks. 1 more thing, is there any way the body of he page to display that strings as text or links ? for example like this , Sam , Jake etc. no forms, i just want it to add that strings automatically at the page whether i type the url or not but strings should be add automatically

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