passing variable in url with smarty - php

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.

Related

Is it possible to add GET statements to a URL when submitting a form to self?

Is it possible to have a link submit to self with GET variables in it?
<a href='#?id=1234&c=2' data-toggle='modal' data-target='#mymodal'></a>
Then when clicked the URL would look like this -
example.com/test.php?msg=hello#?id=1234&c=2
But it doesn't work / PHP doesn't see any of the variables after the #.
I have the following code on the same page (for testing) -
echo $_GET['id'];
And I want it to echo 1234
Is there another way to do this?
Thanks!
If you want the query params you should put them before "#" and not after. When You put them after it, then your php script "won't see" them. Check out this answer on superuser for more.
Also your url example "example.com/test.php?msg=hello#?id=1234&c=2" has 2 "?" in it and it should not.

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

PHP How to pass URL parameter into another URL

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"] ?>" >

PHP Pass variable through URL using ?object=value

I know there's a bunch of these topics out there, but all the answers are simply not working for me. I've tried everything I could find, and I'm still right where I started. I'm trying to pass a variable through a URL:
link
When clicking on the "link", it redirects me to the appropriate page (test2.php), but leaves the value blank (resulting in localhost/test2.php?one=). This means I can no longer see what variable was being sent.
$one = $_GET['one'];
echo $one;
How can I properly send the variable from test.php to test2.php?
Remove quotes from the href value:
link
<!-- ^^^ - quotes missing here -->
you closed the href try this :
link

Carry over arguments to new URL

I am working with some anchor tags in HTML where i need to carry over some arguments from the first url to the second url
My Link
My current URL is - oldpage.html?arg=value
But the "My Link" redirects to -
newpage.html
and not
newpage.html?arg=value
How do i carry over the value of arg ?
If you want to just copy a known variable over, it's as simple as
<?php echo "My Link" ?>
and then oldpage.html?arg=value would produce a link to newpage.html?arg=value.
However, if you want to pass over the entire query string, you can achieve this with the $_SERVER["QUERY_STRING"] variable.
<?php echo "My Link" ?>
This will propagate the entire query string to the new page. So if you accessed the current page with oldpage.html?arg=value&color=green, the link would point to newpage.html?arg=value&color=green.
Alternatively you could use http_build_query, allowing you to add extra parameters or modify the existing query string as you see fit.
<?php echo "My Link" ?>
Using this, navigating to the current page as oldpage.html?arg=value would produce a link to newpage.html?arg=value&foo=bar.
My Link
Or you could do this:
My Link
But that is only if your server allows you to use SERVER variables.

Categories