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