acctman
acctman

Reputation: 4349

Transferring variables $_get to another page

I need to send /files/pvtexp.php?mid=162664&iid=410046&idat=2008/09&sec=2 over to page set.html so I can retrieve the info. I'm trying to get this to work am i missing something?

Page 1:

<?php
$uid = "1500"
$sndlnk = "/files/pvtexp.php?mid=162664&iid=410046&idat=2008/09&sec=2";
?>

<a href="set.html?lnk=$sndlnk&user=$uid"> Send to set.html </a>

Page 2 (set.html):

<?php
$lnk = $_GET['lnk'];
$user = $_GET['uid'];
echo $lnk ."\n";
echo $user ."\n";
?>

Upvotes: 1

Views: 484

Answers (5)

alex
alex

Reputation: 490143

You need to urlencode() $sndlink.

Also, your page is set.html. Have you set up html files to be parsed with PHP?

You could also try this...

<?php
$params = http_build_query(array(
   'lnk' => '/files/pvtexp.php?mid=162664&iid=410046&idat=2008/09&sec=2'
   'user' => '1500'
), '', '&amp;');
?>

<a href="set.html?<?php echo $params; ?>"> Send to set.html </a>

Upvotes: 2

Marc B
Marc B

Reputation: 360572

In your Page 1example, you're setting query parameters of lnk and user

<a href="set.html?lnk=$sndlnk&user=$uid"> Send to set.html </a>
                  ^^^         ^^^^

but in your Page 2 PHP, you're retrieving lnk and uid instead.

$lnk = $_GET['lnk'];
              ^^^
$user = $_GET['uid'];
               ^^^

Since there's no 'uid' in your Page 1 link, $user will come out blank. Change the uid to user on page 1 and things should work a bit better

Upvotes: 1

Grant
Grant

Reputation: 532

For starters you are missing a semicolon.

Should be $uid = "1500";

then include the link in your php using an echo statement like so

echo ('<a href="set.php?lnk='.urlencode($sndlnk).'&user='.urlencode($uid).'">Send to set.html </a>');

Upvotes: 1

Murilo Vasconcelos
Murilo Vasconcelos

Reputation: 4827

You need to encode the variable $sndlnk before sending through the url:

<?php
$uid = "1500"
$sndlnk = urlencode("/files/pvtexp.php?mid=162664&iid=410046&idat=2008/09&sec=2");
?>

<a href="set.html?lnk=$sndlnk&user=$uid"> Send to set.html </a>

At the second page just decode the string:

<?php
$lnk = urldecode($_GET['lnk']);
$user = $_GET['uid'];
echo $lnk ."\n";
echo $user ."\n";
?>

Ok?

Upvotes: 1

Alec Gorge
Alec Gorge

Reputation: 17390

You need to do

<a href="set.html?lnk=<?php echo urlencode($sndlnk); ?>&user=<?php echo $uid; ?>"> Send to set.html </a>

Upvotes: 1

Related Questions