Forum Moderators: coopster

Message Too Old, No Replies

Using Session Data to Query a Different Table

Trying to use the cookie data to single out a row of

         

jwenzel

12:28 am on Jan 24, 2009 (gmt 0)

10+ Year Member



I'm trying to have a user only area on my site where my clients can log on and view their details. I'm having a bit of problems with it though. I'm trying to set this up by taking the username from the session/cookie data and put it in a sql query. The end result being the user will see all information in a table where their username matches the username in the table being queried.

Essentially I'm trying to use the session information to single out a row on a table and display it.

Does this make sense at all? Or is there an easier way to do this?

Thanks

Jon

Here is the code I've been trying to deal with...Clearly its wrong :)

$sql = 'SELECT id, name, username, email FROM clients WHERE username = "<?php . get_username ( $_SESSION['user_id'] ); ?>" ';

penders

6:01 pm on Jan 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$sql = 'SELECT id, name, username, email FROM clients WHERE username = "<?php . get_username ( $_SESSION['user_id'] ); ?>" ';

Presumably this is already in a <?php...?> section, so you don't need to (and shouldn't) escape your PHP again...

<?php 
// PHP code....
$sql = 'SELECT id, name, username, email FROM clients WHERE username = "' . get_username($_SESSION['user_id']) . '"';
// More PHP code to execute your query....
?>

jwenzel

7:06 pm on Jan 27, 2009 (gmt 0)

10+ Year Member



Thanks penders...YOU are the man. It works beautifully