p_tru Posted March 9, 2006 Share Posted March 9, 2006 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.pictureFROM item i, Recommended_item r, p_history p, customer cWHERE r.item1_id = p.ItemNoAND r.item2_id = i.item_idAND p.customer_id = c.customer_idAND 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 1plz help mePetey Quote Link to comment https://forums.phpfreaks.com/topic/4490-using-sessions-is-sql-query-on-other-pages/ Share on other sites More sharing options...
sgb162 Posted March 9, 2006 Share Posted March 9, 2006 session_start is a necessity on any pages using sessions. Try getting it in at the top and see if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/4490-using-sessions-is-sql-query-on-other-pages/#findComment-15637 Share on other sites More sharing options...
p_tru Posted March 9, 2006 Author Share Posted March 9, 2006 [!--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 helpPetey Quote Link to comment https://forums.phpfreaks.com/topic/4490-using-sessions-is-sql-query-on-other-pages/#findComment-15733 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.