zerey
zerey

Reputation: 871

pass variable from href to another php page

.I have this code:

<a id="various3" href="picture.php?id=',$pid,'" title="'.$info.'"><img src="picture.php?id=',$pid,'" width="150" height="210"></a>

it passes the id to my picture.php where i use it on a query string.

$sql = sprintf("select pics, ext from `06-07` where id='%d'",$_GET['id']);

Is it possible to pass more than one variable using this method? because i would like to pass "dept" along with the "id". if it is then how?

I have tried this:

<a id="various3" href="picture.php?id=',$pid,'&dept=',$dept,'" title="'.$info.'"><img src="picture.php?id=',$pid,'&dept=',$dept,'" width="150" height="210"></a> 

with matching

$sql = sprintf("select pics, ext from 06-07 where id='%d' AND dept='%s'", $_GET['id'], $_GET['dept']); but it doen't work. what's wrong?

Upvotes: 3

Views: 29353

Answers (4)

laxmi kalake
laxmi kalake

Reputation: 159

<a href="test.php?page_name=<?php echo $this_month; ?>">

access this on another page by get method:

$file_name = $_GET['page_name'];

Upvotes: 9

h00ligan
h00ligan

Reputation: 1481

Based on your examples the query string is going to be pretty strange.

First off, you're trying to use single quotes around the variable values.

Second, is the line a part of a print/echo statement? As it is now it seems you're not printing the PHP variables at all so you'll most likely just get the variable name as part of the url.

Assuming the example line you've given is NOT a part of a print/echo statement:

<a id="various3" href="picture.php?id=<?= $pid ?>&dept=<?= $dept ?>" title="<?= $info ?>"><img src="picture.php?id=<?= $pid ?>&dept=<?= $dept ?>" width="150" height="210"></a>

If the example line is a part of a print/echo statement:

print '<a id="various3" href="picture.php?id='.$pid.'&dept='.$dept.'" title="'.$info.'"><img src="picture.php?id='.$pid.'&dept='.$dept.'" width="150" height="210"></a>';

Upvotes: 0

naiquevin
naiquevin

Reputation: 7796

Yes it is possible to pass more than 1 parameters in the get request using something like

picture.php?id=1&dept=xyx&...

But note that whatever you pass this way will be visible in the browser, so don't use this method to pass something that the user should not know.

Also, is there a typo in the code ? Instead of picture.php?id=',$pid,', it should be picture.php?id=' . $pid . ' or picture.php?id=<?php echo $pid; ?> right ?

Upvotes: 0

Ikke
Ikke

Reputation: 101221

You can chain get parameters with the & sign like this:

index.php?id=1&depth=2

Upvotes: 0

Related Questions