c_pate Posted December 4, 2008 Share Posted December 4, 2008 Hi, i have a link that calls a function that will return a link. i wanted to send with this link a variable $fname, however when i click check the array on the page it takes the variable literraly instead of putting its value in. here is the code: function writeShoppingCart() { ... return '<p>You have <a href="cart.php?fname=$fname">'.count($items).' item'.$s.' in your shopping cart</a></p>'; ... } i would like the link to be cart.php?fname=cpate instead i get cart.php?fname=$fname. Thanks for you help... Quote Link to comment https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/ Share on other sites More sharing options...
GingerRobot Posted December 4, 2008 Share Posted December 4, 2008 See this post: http://www.phpfreaks.com/forums/index.php/topic,211483.msg963158.html#msg963158 Quote Link to comment https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/#findComment-705996 Share on other sites More sharing options...
c_pate Posted December 4, 2008 Author Share Posted December 4, 2008 Hey, I tried that already and it didn't work for me. it just sends back blanks. Quote Link to comment https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/#findComment-706005 Share on other sites More sharing options...
MadTechie Posted December 4, 2008 Share Posted December 4, 2008 function writeShoppingCart() { ... return "<p>You have <a href=\"cart.php?fname=$fname\">".count($items)." item".$s." in your shopping cart</a></p>"; ... } Quote Link to comment https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/#findComment-706012 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Another working example.. function writeShoppingCart() { ... return '<p>You have <a href="cart.php?fname=' . $fname . '">'.count($items).' item'.$s.' in your shopping cart</a></p>'; ... } Or even function writeShoppingCart() { ... return '<p>You have <a href="cart.php?fname={$fname}">'.count($items).' item'.$s.' in your shopping cart</a></p>'; ... } It is just a matter of preference. Me I like to go in and out so I know where my variables are when I look at my code. Quote Link to comment https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/#findComment-706022 Share on other sites More sharing options...
c_pate Posted December 4, 2008 Author Share Posted December 4, 2008 Thanks alot for your helps guys, it turn out i need to send the variable $fname to the function before i can use it. i just assumed that since its on the same page the variables are global. Quote Link to comment https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/#findComment-706027 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.