Jump to content

[SOLVED] Displaying Data Based On Current User ID - Need Help


brainstorm

Recommended Posts

Hi All,

 

I have a page called "myaccount.php" where I want a client to go and only see their information. right now, the page displays all client rows and I can't seem to figure out how to sort by the data by current user...Any help is greatly appreciated!

 

This is what I have so far...

 

Thanks!

Session verify:

<?php
session_start();

if (!isset($_SESSION['user']))
{
die ("Access Denied");
}

?>

 

Display table;

<?php
      include 'dbc.php';
  $data = mysql_query("SELECT * FROM users order by full_name where user_email LIKE ".$_SESSION['user']."")
  or die(mysql_error());
  Print "<table border=1 cellpadding=2 cellspacing=0 width=100%>
  <tr>
	 <td valign=top align=left><strong>Name</strong></td>
	 <td valign=top align=left><strong>Address</strong></td>
	 <td valign=top align=left><strong>Joined</strong></td>
	 <td valign=top align=left><strong>Email</strong></td>
         </tr>";
 while($info = mysql_fetch_array( $data ))
   {
	Print "<tr>";
	Print "<td bgcolor=#accbed>".$info['full_name'] . "</td> ";
	Print "<td>".$info['address'] . "</td> ";
	Print "<td>".$info['joined'] . "</td> ";
	Print "<td>".$info['user_email'] . "</td></tr> ";

	}
	Print "</table>";
?>

Try modifying your query to something like:

"SELECT * FROM users WHERE user_email = {$_SESSION['user']} ORDER BY full_name"

 

I just tried it and I got the following error within the page.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@earthlink.net ORDER BY full_name' at line 1

Maybe try

"SELECT * FROM users WHERE user_email = '{$_SESSION['user']}' ORDER BY full_name"

OR

"SELECT * FROM users WHERE user_email = \"{$_SESSION['user']}\" ORDER BY full_name"

 

The second line worked!!!! I'm all set guys! Thank you so much for your help!!!!!!

 

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.