Jump to content

Recommended Posts

back again :) ok now i got problem getting $ to the $cid which i fetch from $_SESSION it only prints the string not the $ and i have email ids stored by cid and if i do not get a $ in front of the cid the emails does not show up. whats the solution guys?

 

$cid = $_SESSION['cid'];

 

 

$to = $fData['email'];

$to_company = "$cid";

Edited by lovephp
Link to comment
https://forums.phpfreaks.com/topic/269131-hlp-adding-a-to-string/
Share on other sites

Variables are parsed within a double-quoted string.

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

 

As you can see in the manual, in order to get a literal $, you must escape it with a leading backslash.

ok i explain again :tease-01:

 

Global $cid01;

Global $cid02;

 

now $cid01 and $cid02 got email id stored in variable and $cid = $_SESSION['cid']; fetches only cid01 without $

 

when i add like this $to_company = "$cid01"; email sends but when i try $to_company = "$cid"; no email gets send

You're doing it wrong. SOmewhere, some how, you're doing it wrong, but we honestly can't figure out what because none of this makes any sense.

 

What do you HAVE: Show us the current value of $_SESSION['cid']. By itself. Not in a paragraph, not in a line of code, inside a [ code ] box by itself.

 

What do you NEED: Show us the line of code without a variable in it that works. If you want $to_company = 'abc123' but $cid = 'abc', show us that.

i really apologize for my way of writing. im not very good in explaining things.

 

i actually want $to_company = 'abc123'; to be like want $to_company = '$abc123'; but currently its not happening the way i am doing

 

  $cid = $_SESSION['cid'];


  $to = $fData['email'];
  $to_company = "$cid";

 

the code above only prints $to_company = 'abc123'; i believe

It sounds to me you want variable variables, which is also a 'You're doing it wrong!' situation.

 

If I'm understanding right you have for example:

$cid01 = 'some content';
$cid02 = 'some other content';

 

And then then $_SESSION['cid'] contains a value like 'cid01'; which you want to use to find that variable, eg:

$cid = $_SESSION['cid']; //(ex 'cid01')
echo $cid; //(you want to echo 'some content';

 

The syntax for that would be:

$cid = $_SESSION['cid']; //(ex 'cid01')
echo $$cid; //double-dollar sign

 

However as mentioned, this is the wrong way to do it. Rather than numbered cid varibles, use an array to store you're content, then just index into that array:


$cidcontent = array(
 'some content',
 'some other content'
);

$cid = $_SESSION['cid']; //stores the number 1 for example
echo $cidcontent[$cid]; //outputs 'some other content';

It sounds to me you want variable variables, which is also a 'You're doing it wrong!' situation.

 

If I'm understanding right you have for example:

$cid01 = 'some content';
$cid02 = 'some other content';

 

And then then $_SESSION['cid'] contains a value like 'cid01'; which you want to use to find that variable, eg:

$cid = $_SESSION['cid']; //(ex 'cid01')
echo $cid; //(you want to echo 'some content';

 

The syntax for that would be:

$cid = $_SESSION['cid']; //(ex 'cid01')
echo $$cid; //double-dollar sign

 

However as mentioned, this is the wrong way to do it. Rather than numbered cid varibles, use an array to store you're content, then just index into that array:


$cidcontent = array(
'some content',
'some other content'
);

$cid = $_SESSION['cid']; //stores the number 1 for example
echo $cidcontent[$cid]; //outputs 'some other content';

 

yes yes u got me right

Ok I'm done with you, I asked way too many times for the value of $cid and you just can't figure out how to answer me. Perhaps PHP is not for you.

 

You don't have a variable called $cid. That's pretty obvious. You have $cid01. Why not just use $cid01? You have code that works. How is "ok it works" not the end of the conversation?

 

 

Ok I'm done with you, I asked way too many times for the value of $cid and you just can't figure out how to answer me. Perhaps PHP is not for you.

 

You don't have a variable called $cid. That's pretty obvious. You have $cid01. Why not just use $cid01? You have code that works. How is "ok it works" not the end of the conversation?

 

bro very sorry the value of $cid is cid01 which is in the session and Global $cid01 got a email id stored against it so does Global $cid02 and from session $cid either could come cid01 or cid02 which is coming anyways but just that when i use it in $to_company = "$cid"; no email gets sends

Edited by lovephp
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.