bhavin_85 Posted February 19, 2007 Share Posted February 19, 2007 hi guys i have set a customer id which i want to be carried over to the next page, this work fine but i now want to write a query which will take that customer id, match it to the customer id in the database and then extract that row of information about the user <? session_start(); if ( empty($_SESSION['username'])){ header("location:default.php"); exit; } $id=$_SESSION['cust_id']; include('config.php'); $sql="SELECT * FROM customer WHERE cust_id='$id'"; $query=mysql_query($sql); if (mysql_num_rows($query) != 0) { $row = mysql_fetch_assoc($query); } ?> thats the code ive written but it doesnt seem to work...can some1 give me an idea of where im going wrong cheers Link to comment https://forums.phpfreaks.com/topic/39177-solved-session-question/ Share on other sites More sharing options...
trq Posted February 19, 2007 Share Posted February 19, 2007 Try this and let us know the output. $query=mysql_query($sql) or die(mysql_error()); Your code looks fine. Link to comment https://forums.phpfreaks.com/topic/39177-solved-session-question/#findComment-188674 Share on other sites More sharing options...
skali Posted February 19, 2007 Share Posted February 19, 2007 print $sql="SELECT * FROM customer WHERE cust_id='$id'"; will let you know if your query is OK. if it is and your connection is OK then post the error if you are getting any. Link to comment https://forums.phpfreaks.com/topic/39177-solved-session-question/#findComment-188678 Share on other sites More sharing options...
bhavin_85 Posted February 19, 2007 Author Share Posted February 19, 2007 hey guys the query is working, now i need to figure out why its not printing the right information...maybe the session variables are not set right? <? session_start(); if ( empty($_SESSION['username'])){ header("location:default.php"); exit; } $id=$_SESSION['cust_id']; include('config.php'); $sql="SELECT * FROM customer WHERE cust_id='$id'"; $query=mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) != 0) { $row = mysql_fetch_assoc($query); } print $sql="SELECT * FROM customer WHERE cust_id='$id'"; ?> <html> <head> <title>P.B.L. Jewellers Ltd</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#030102" text="#666666"> <div> <table width="670" height="546" border="0" align="center" bordercolor="#000000"> <tr> <td colspan="2" align="right"> <? echo "You are logged in as " . $_SESSION['uname'] . ""?> <a href="default.php">Logout</a> </td> </tr> <tr> <td colspan="3"> <img src="images/banner2.png" width="670" height="158" align="top"> </td> </tr> <tr> <td colspan="3" align="center"><? readfile("menu.inc"); ?> </td> </tr> <tr> <td><? echo print_r($_SESSION)?></td></tr> <tr> <td><br><? echo "Hello " . $_SESSION['first_name'] . "" ?></td> </tr> <tr> <td><p> </p> Personal Information <br> <? echo "Customer ID: " . $_SESSION['cust_id'] . "<br>"; echo "Name: " . $_SESSION['first_name'] . " " . $_SESSION['surname'] . "<br>"; echo "Address: " . $_SESSION['address1'] . ", " . $_SESSION['address2'] . "<br>"; echo "Town: " . $_SESSION['town'] . "<br>"; echo "County: " . $_SESSION['county'] . "<br>"; echo "Postcode: " . $_SESSION['postcode'] . "<br>"; echo "Status: " . $_SESSION['status'] . "<br>"; ?> </p></td> <td>Loyalty Points</td> </tr> </table> </div> </body> </html> All of the sessions that ive decliared above are rows in the table, i thought that is all i needed to do? or am i wrong Link to comment https://forums.phpfreaks.com/topic/39177-solved-session-question/#findComment-188717 Share on other sites More sharing options...
bhavin_85 Posted February 19, 2007 Author Share Posted February 19, 2007 never mind i figured it out..... i forgot to set the session variables properly...opps lol no wonder it was bring up the wrong info! cheers 4 the help guys Link to comment https://forums.phpfreaks.com/topic/39177-solved-session-question/#findComment-188741 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.