Using a sending information through a link

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Using a sending information through a link

Post by nigma »

Is there a way I can do something like

<a href="viewScreenshot.php" name="screenshot" value="sc1.bmp">

then when you click it viewScreenshot.php gets the value of the link
( screenshot ) and then opens up the picture sc1.bmp ( because that is value of screenshot )??

Thanks for all help provided.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

href can't have a value assigned. Try "<a href='viewscreenshot.php?id=screenshot1'>ScreenshotName</a>".
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

If I did that how would I call its ID in viewScreenshot.php?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

appending key/value-pairs to the url is called GET-method (same as setting method="GET" for a form).
In recent versions of php they are stored in the superglobal array $_GET
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

So it would be $_GET['id']??
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

How would I store what was after the ?id=whatiwanttostore in a variable?
CONFIQ
Forum Commoner
Posts: 32
Joined: Fri Oct 18, 2002 3:39 pm
Location: Israel - Raanana

Post by CONFIQ »

id=value&variable=value
Than $_GET['id] is value and $_GET['variable] is value
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Here is the link: <a href="viewScreenshot.php?id=sc1.bmp">

Here is viewScreenshot.php:

<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

<div align="center">

<?php

$picToView = $_GET['id];

echo("<image src=\"$picToView\">");

?>

</div>

</body>

</html>

Why doesn't this work?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Code: Select all

<?php
$_GET['id]; 
?>
should be

Code: Select all

<?php
$_GET['id']; 
?>
Make sure the image is in the same directory as the script. Otherwise you'll have to specify where the image-folder is (e.g. "../screenshots/").
Post Reply