Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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