homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Problem passing variables in url
with $_GET[ ]
Sarah Atkinson

 4:50 pm on May 11, 2005 (gmt 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)

What is the example url of this page?

Sarah Atkinson

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




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

Your url's look fine and the encode correctly. Lets see the code of the page that the variables are being passed to.

Sarah Atkinson

 2:40 pm on May 12, 2005 (gmt 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)

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved