Jump to content

Variables Question


ironside82

Recommended Posts

I am trying to include html and php in a variable. here is an example of code:

 

$msg = '<p><? echo $friend_firstname; ?> <? echo $friend_lastname; ?> (<? echo $friend_username; ?>) wants to add you as a friend. <a href="viewprofile.php?profile_id=<? echo $friend_id; ?>">View their profile</a></p><p><a href="req_friend.php?friendid=<? echo $user_id ?>">Add them as a friend</a></p>';

 

this information that the variable provides is then inserted into a database.

 

when recalled from the database it should output:

 

 

Joe Bloggs (joeb33) wants to add you as a friend

View their profile //-> links to viewprofile.php?profile_id=8

Add as a friend //-> links to req_friend.php?friend_id=6

 

how ever it appers that the PHP elements that are encapsulated in the ' ' are not making their way thorough when their are later output again from the database.

 

Is this an issue with the way the information in that variable to inserted in the database or when it is later echoed to a users inbox?

 

It a little complicated to explain.

 

Thanks again

 

James

 

 

 

Link to comment
Share on other sites

$msg = "<p>$friend_fristname $friend_lastname $friend_username wants to add you as a friend.";
$msg .= "<a href=\"viewprofile.php?profile_id=$friend_id\">View their profile</p><p>";
$msg .= "<a href=\"req_friend.php?friendid=$user_id\">Add them as a friend</p>";

 

think thats what ur lookin 4

 

Link to comment
Share on other sites

Explanation:

$msg = '<p><? echo $friend_firstname; ?> <? echo $friend_lastname; ?> (<? echo $friend_username; ?>) wants to add you as a friend. <a href="viewprofile.php?profile_id=<? echo $friend_id; ?>">View their profile[/url]</p><p><a href="req_friend.php?friendid=<? echo $user_id ?>">Add them as a friend[/url]</p>';

 

 

' ' = literal, so your page was outputting <? echo $friend_fristname ?> and not processing it, and u dont need the <? ?> in thereunless u were using php to generate a php page source, which im almost positive ur  not :P cuz thats kinda pointless unless ur in high end development :/

useing " lets php replace all those variables, and on your html code, dont' forget to escape " : href="blah blah" should be href=\"blah blah\" in php code :P

Link to comment
Share on other sites

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.