Jump to content

Using Sessions is sql query on other pages


p_tru

Recommended Posts

Hi All,

I am trying to get the username for a particular user using sessions when he/she logs in from the database, then use that username in a sql query to get the require information.

My code is:

[code]
<?php include('head.inc'); ?>
<?php
$variable = session_name( );

echo '<table><tr>';
echo $_SESSION['username'];
$list ="SELECT i.title, i.cost, i.picture
FROM item i, Recommended_item r, p_history p, customer c
WHERE r.item1_id = p.ItemNo
AND r.item2_id = i.item_id
AND p.customer_id = c.customer_id
AND c.username = '".$_SESSION['username']."'";
$list_result = @mysql_query($list,$conn);
while ($row= mysql_fetch_array($list_result, MYSQL_ASSOC)){

echo'<td><img class="image" width =60px height =100px src="' .$row["picture"].  '" alt="picture"/><br>
<a href="User.php?id=' .$row['Title'] . '">' .$row['cost'].  '</a><br>' .$row['cost']. '<br><h1>Recomended Items</h1></td></tr><tr>';
}
echo '</tr></table>';
?>
</td>
<?php include('foot.inc');?>[/code]

All i get from the page is my template and the number 1

plz help me

Petey
Link to comment
Share on other sites

[!--quoteo(post=353104:date=Mar 9 2006, 01:27 AM:name=sgb162)--][div class=\'quotetop\']QUOTE(sgb162 @ Mar 9 2006, 01:27 AM) [snapback]353104[/snapback][/div][div class=\'quotemain\'][!--quotec--]
session_start is a necessity on any pages using sessions. Try getting it in at the top and see if that helps.
[/quote]


I try session_start(); but its still just showing the number 1, i heard that i might have to set the session to the username, is this right, because i am guessing at the moment the session is only getting one because it is returnin if it is true or not, [b]HOW DO I SET THE SESSION TO THE USERNAME AND WOULD THIS SOLVE THE PROBLEM???[/b]

plz help

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