Jump to content


Photo

Using Sessions is sql query on other pages


  • Please log in to reply
2 replies to this topic

#1 p_tru

p_tru
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 March 2006 - 01:07 AM

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:

<?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');?>

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

plz help me

Petey

#2 sgb162

sgb162
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 09 March 2006 - 01:27 AM

session_start is a necessity on any pages using sessions. Try getting it in at the top and see if that helps.

#3 p_tru

p_tru
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 09 March 2006 - 11:07 AM

[!--quoteo(post=353104:date=Mar 9 2006, 01:27 AM:name=sgb162)--][div class=\'quotetop\']QUOTE(sgb162 @ Mar 9 2006, 01:27 AM) View Post[/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, HOW DO I SET THE SESSION TO THE USERNAME AND WOULD THIS SOLVE THE PROBLEM???

plz help

Petey




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users