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
https://forums.phpfreaks.com/topic/89078-variables-question/
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
https://forums.phpfreaks.com/topic/89078-variables-question/#findComment-456205
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
https://forums.phpfreaks.com/topic/89078-variables-question/#findComment-456207
Share on other sites

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.