/    Sign up×
Community /Pin to ProfileBookmark

GET variable from URL, echo in the same page

I have a php page that contains images as links. I want that when I click the image, I remain on the same page, but get the name of the city that the image contains.

My code:

[CODE]<div class=”den_stema2″>
<a href=”#?link=nisporeni”>
<img src=”Nisporeni/Poze/stemaNisporeni.jpg” />
</a>
</div>

<div class=”den_stema2″>
<a href=”#?link=orleans”>
<img src=”Orleans/Poze/stemaOrleans.jpg” />
</a>
</div>

<div class=”den_stema2″>
<a href=”#?link=szekszard”>
<img src=”Szekszard/Poze/stemaSzekszard.jpg” />
</a>
</div>

<div class=”desc_stema”>
<p><a href=”#?link=nisporeni”>Nisporeni</a></p>
</div>

<div class=”desc_stema”>
<p><a href=”#?link=orleans”>Orleans</a></p>
</div>

<div class=”desc_stema”>
<p><a href=”#?link=szekszard”>Szekszard</a></p>
</div>

Cod: Selecta&#355;i tot[/CODE]

And in the same page:

[CODE] <?php $city = $_GET[‘link’]; //line 353
echo $city;
?>[/CODE]

[QUOTE]

Notice: Undefined index: link in C:UwAmpwwwPrimariaContinut_siteDespre_LugojOrase_infratiteorase_infratite.php on line 353

[/QUOTE]

I tried to declare “$link=”;” before the whole code, but same Notice.

Thank you!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmDec 24.2015 — I see a bunch of html and 2 lines of PHP that are completely out of context. You do realize that the GET array will not exist until the html anchor is clicked? Where is the check that the GET actually exists? Where is the PHP code placed - in front of the html or right after it?
Copy linkTweet thisAlerts:
@kostas13ioannouDec 24.2015 — I think the best way to do this, is with javascript.

Pass the name that you want in your link, into an attribute, (example rel='London'),

and with javascript get it, show it, and put it into your url!
Copy linkTweet thisAlerts:
@ginerjmDec 25.2015 — I'm gonna guess that the OP doesn't know how to do that based on his current question. That said - I have to ask the OP - why don't you just assign a "title=' attribute to the img tags so that the user merely has to scroll over the image?
Copy linkTweet thisAlerts:
@sunLotusauthorDec 29.2015 — the php code is after the html
Copy linkTweet thisAlerts:
@sunLotusauthorDec 29.2015 — [I]orase_infratite.php[/I] is the same page where i want to get the city name.

Solved it. Seems it works when like this:

<a href="[B][COLOR="#FF8C00"]orase_infratite.php[/COLOR][/B]?link=corint" title="corint">

<img src="Corint/Poze/stemaCorint.jpg" width="108"/>

</a>

I can get the city name, "corint":

$oras = $_GET['link'];

It not works when like this:

<a href="[COLOR="#FF8C00"][B]#[/B][/COLOR]?link=corint" title="corint">

<img src="Corint/Poze/stemaCorint.jpg" width="108"/>

</a>
Copy linkTweet thisAlerts:
@NogDogDec 29.2015 — Yep, anything after the "#" is just used for an anchor within the page (unless you implement JavaScript code to do otherwise with it). Anything that follows it is not (natively) part of the query string.
×

Success!

Help @sunLotus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...