Welcome to WebmasterWorld Guest from 54.205.20.160

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)

10+ Year Member



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)

10+ Year Member



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

10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month