views:

33

answers:

2

I am trying to create a page that displays a preview of all the data that each individual user has put into the database. Each user must only be able to see their own data.

I have been using $SESSION's to post which logged in user is inputting what, and have tried to get my brain to think about the reverse action.

I first wondered whether I could do

SELECT * FROM input WHERE input.bodyshop_name=$_SESSION ['MM_Username']

But that did not work.

As you can probably tell, I am new to PHP/MySQL, so any help would be appreciated.

Thanks

+1  A: 

if bodyshop_name is the username of the user who input that data, then a query like you said should work.

make sure $_SESSION['MM_Username'] is in single quotes when you write the query.

GSto
+1  A: 

You will want to try this

$sql = "SELECT * FROM `input` WHERE `input`.`bodyshop_name`='".mysql_real_escape_string($_SESSION['MM_Username'])."'";

Note the use of mysql_real_escape_string to sanatize any unwanted data.

Lizard
Thank you. Just one last question, what would the funtion be called please, I'm struggling a little?
Lisa
I'm not sure what function you are after... what are you trying to achieve?
Lizard
I want to call up all the records that relate to the logged in user. I think the function will be read_input, but I am not quite sure as it's not going to input, it will call down those records.
Lisa