Jump to content

[SOLVED] session question


bhavin_85

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

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