Welcome to WebmasterWorld Guest from 54.167.102.69

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem passing variables in url

with $_GET[ ]

     
4:50 pm on May 11, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 29, 2003
posts:424
votes: 0


how do you code a href with php verriables in it?
here are some ways I have tried

<a href="<?php echo "viewmenu.php?fromwhere=$fromwhere&xdate=$xdate&zdate=$zdate"?>">BACK</a>

echo ("<td><a href='editmenu.php?id=" . $id . '&fromwhere=' . $fromwhere . '&xdate=' . $x . '&zdate=' . $z . "'>Edit</a><br />");

5:11 pm on May 11, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 23, 2003
posts:46
votes: 0


What is the example url of this page?
5:28 pm on May 11, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 29, 2003
posts:424
votes: 0


viewmenu.php?fromwhere=tablename&xdate=2005-05-1&zdate=2005-05-10

editmenu.php?id=5&fromwhere=tablename&xdate=2005-05-1&zdate=2005-05-10

10:33 am on May 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 30, 2004
posts:95
votes: 0


Your url's look fine and the encode correctly. Lets see the code of the page that the variables are being passed to.
2:40 pm on May 12, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 29, 2003
posts:424
votes: 0


I think i have all my code working. <knocks on partical board desk>.

But out of the two ways I posted are both legal and if so which is better?

3:07 pm on May 12, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


Depends what you are doing. The second method is more complicated (you can make a mistake much easier), and the first meets the eye. However with the first method you can't put there any value from association array nor call a function. That means you can't write:

<a href="<?echo "viewmenu.php?fromwhere=$_POST['fromwhere']&date=date('Y-m-d')";?>
where with second way you may do it:
<a href="<?echo "viewmenu.php?fromwhere=".$_POST['fromwhere']."&date=".date('Y-m-d');?>

It's really up to you which method you use. I use both - when I can I use first, when it's not possible I use dots.

Hope this helps
Michal Cibor

3:08 pm on May 12, 2005 (gmt 0)

New User

10+ Year Member

joined:Apr 8, 2004
posts:12
votes: 0


I hate escaping in and out of PHP, so I like the latter.