Jump to content

PHP Function does return properly


c_pate

Recommended Posts

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...

 

Link to comment
https://forums.phpfreaks.com/topic/135524-php-function-does-return-properly/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.