PHP How to pass URL parameter into another URL - php

I have a URL with a parameter
www.url.com/page.php?n=name
Now, within a page.php I need to create a hyperlink that works with that parameter. I now have
<a href="page2.php?a=param2&n=<?php $_GET["n"] ?>" >
but this does not work and the URL shows with empty parameter "n":
http://www.url.com/page2.php?a=param2&n=
Could you please help me to pass that parameter in the hyperlink? Kindly thank you in advance.

You need to do <?php echo $_GET["n"] ?>
The echo actually prints it into the code. You were just calling it.

You need to echo the PHP out so it is echoed out to the HTML, and is then in the source code.
Like so:
<a href="page2.php?a=param2&n=<?php echo $_GET["n"] ?>" >

Related

PHP How to correctly echo a link?

What is the correct way to echo a link to another page in php? I have seen this used but it doesn't work?
echo "<p><a href=\"link\">";
Html in PHP
<?php
echo "<a href='$link'>The Link You Want</a>";
?>
Php in Html
Link
It seems like your question was already answered in How to create a link to another PHP page
Index Page
Page 2
If you need to pass a value -
Link that pass the value 1
You would do it like this:
print("<a href='your_target'></a>");
Or if you want to print the code and not the link:
print(htmlspecialchars("<a href='your_target'></a>"));
try this:
<a href='<?php echo "the_page_you_want.php" ?>'>link_text</a>

How to pass parameters in url using php page

here i am trying to pass the id as parameter for next page using php.
I am retrieving values from database and i have id as a primary key. i want to pass the id for next page. but when i pass the parameter through URL its not appearing on url. how can i do this?
here is what i have done.
echo "<a href='product-des.php?'". $row["product_id"].">";
here the URL is visible till.php but i am not able to see any id after that.
what am i doing wrong here... how can i do this?
To pass parameter
echo '<a href="product-des.php?pro_id='. $row["product_id"].'">';
To get parameter:
echo $_GET['pro_id'];
this
echo "<a href='product-des.php?'". $row["product_id"].">";
should be like this
echo "<a href='product-des.php?product_id=".$row['product_id']'>."'" >Product Name</a>";
try this

Multiple URL parameters?

I am using Dreamweaver and would like to add multiple parameters to my my link. Right now I have one parameter which works fine, but I would like to add multiple parameters to the same link, how do I do that?
The code to the link is as follows:
<a href="Patient.php?Patient=<?php echo
$row_Patienter['Patient']; ?>">Visa</a>
This does links to another page's Recordset.
My question is:
How do I add multiple parameters to the same link? How would it look like?
You can separate parameters by adding a & at the end of each parameter.
Something like:
http://www.domain.com?parameter1=value1&parameter2=value2
But in your case I would recommend to do it like this:
<?php
echo "<a href='patien.php?parameter1=".$value1."&parameter2=".$value2."'>Link</a>";
?>
You add extra parameters by starting with ? and adding & each time you start a new parameter. Remember in HTML to use &
Visa
<a href="bar.php?foo=<php echo $foo; ?>&bar=<?php echo $bar; ?>">
or whatever the values are. Better use echo, not sure what you wrote works

passing variable in url with smarty

here is an existing link
<a class="link-item" href="{#url_site#}/plongee-{$post.nom_pays|sluggable}/{$post.nom_forfait|sluggable}-{$post.id_forf}">Voir l'offre</a>
I am trying to pass a variable to the next page.
I have added:
<a class="link-item" href="{#url_site#}/plongee-{$post.nom_pays|sluggable}/{$post.nom_forfait|sluggable}-{$post.id_forf}?test=test">Voir l'offre</a>
the next page url is
http://dev.amv-voyages.fr/plongee-egypte/dune-sejour-plongee-petit-budget-safaga-sans-vols-1387?test=test
but
echo '<pre>get';
print_r($_GET);
echo '</pre>';
returns empty.
Please help :)
<a class="link-item" href="{#url_site#}/plongee-{$post.nom_pays|sluggable}/{$post.nom_forfait|sluggable}-{$post.id_forf}&test=test">Voir l'offre</a>
Please try this as already there are multiple slashes it means in the rewrite rule already the '?' is used to take the first parameter so all other parameters should use '&' after the first one.

How to pass URL in URL (as GET parameter) using PHP?

I'm having some problems passing URL's as GET parameter. When I try to access:
http://www.linkebuy.com.br/linkebuy/parceiro?url=http%3A%2F%2Fwww.google.com
I get the following message:
However, if I go for:
http://www.linkebuy.com.br/linkebuy/parceiro?url=123
Everything works just fine (it redirects to an inexistent site - 123 -, of course, but it does the expected). By elimination I can say there's something wrong with the url parameter, but what is it?
OBS: I'm using rawurlencode() to encode the URL.
EDIT: Code you asked...
In the first view, where the link is (http://www.linkebuy.com.br/notebook/detalhe?id=5):
<!-- url() function just completes the right URL (production or development) -->
<a href="<?php echo url('linkebuy/parceiro/?url=' . rawurlencode($l->getUrl()), true) ?>" class="<?php echo $leadClass ?> oferta" target="_blank">
<?php echo $l->getNomeFantasia() ?>
</a>
When clicked the link redirects to an action (/linkebuy/parceiro), where happens the following (basicly nothing, just keeping in the framework):
public function execute($request, $response) {
$response->addParameter('url', rawurldecode($request->getParameter('url', ''))); //This creates $url in the view
$response->setTemplate('site/linkebuy/lead-parceiro.php'); //Forwards to the view
}
It includes the view, lead-parceiro.php (above on the question, I link to this page), where the head contains:
<script type="text/javascript">
setInterval(function(){ window.location = '<?php echo $url ?>'; },3000);
</script>
If you can't get rid of the restriction you can pass the url in 2 parts like this
http://www.linkebuy.com.br/linkebuy/parceiro?protocol=http&url=www.google.com
And then parse it on your code to make the full url for the redirect.
You should use urlencode when you pass anything as URL parameter

Categories