Jump to content

Linking, sessions. Help.


unsider

Recommended Posts

I currently am trying to create a more interconnected site, and what better way to do that than to have a link to that particular user's profile than when he submits a comment. The link to his profile will be in in his username, I'm sure you've all seen a system that works this way.

 

<a href="example.com/main/index.php?userinfo=$displayed username">$displayed username</a>

 

Excerpt from code, but it's all that is necessary.

 

<?php

$query  = "SELECT id, commenttext, username FROM comments LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');


echo '<table div class="tborder">';

$username = $_SESSION['username'];

while($row = mysql_fetch_array($result))
{


echo '<tr class="tr' . $tr . '"><td>' . '<img src="http://example.com/main/images/post.gif">' . '<a href="userinfo.php?user=$username">' . $row["username"] . '</a>' . '<br>' . ' posted on: ' . '<br><br>' . ' ' . $row["commenttext"] . '</td></tr>'; 


// etc....

?>

 

NO ERRORS, but this is the URL it displays:

 

http://example.com/main/userinfo.php?user=$username

 

Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/96196-linking-sessions-help/
Share on other sites

It's because you are using single quotes instead of double.

 

Try this:

<?php

$query  = "SELECT id, commenttext, username FROM comments LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');


echo '<table div class="tborder">';

$username = $_SESSION['username'];

while($row = mysql_fetch_array($result))
{

echo '<tr class="tr' . $tr . '"><td>' 
. '<img src="http://example.com/main/images/post.gif">' 
. "<a href='userinfo.php?user=$username'>" . $row["username"] 
. '</a>' . '<br>' . ' posted on: ' . '<br><br>' 
. ' ' . $row["commenttext"] 
. '</td></tr>'; 


?>

Link to comment
https://forums.phpfreaks.com/topic/96196-linking-sessions-help/#findComment-492444
Share on other sites

you must concatenate variables into strings with the literal single quote.

 

Single quote strings are Literal (Meaning anything inside will stay as-is and wont call functions/variables etc without concatenation)

All Double Quote strings are Dynamic/Variable (dont know the exact name :/) can use specific functions/variables without concatenating.

 

 

hope this helps,

Link to comment
https://forums.phpfreaks.com/topic/96196-linking-sessions-help/#findComment-492450
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.