简体   繁体   中英

PHP/ MySQL: What is the best way to get filtered data from a database that has been inputted by a logged in user?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM