简体   繁体   English

PHP / MySQL:从登录用户输入的数据库中获取过滤数据的最佳方法是什么?

[英]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. 我一直在使用$ SESSION来发布哪个登录用户正在输入什么,并且试图让我的大脑思考反向操作。

I first wondered whether I could do 我首先想知道我是否可以做

SELECT * FROM input WHERE input .bodyshop_name=$_SESSION ['MM_Username'] SELECT * FROM input哪里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. 如您所知,我是PHP / MySQL的新手,所以将不胜感激。

Thanks 谢谢

if bodyshop_name is the username of the user who input that data, then a query like you said should work. 如果bodyshop_name是输入该数据的用户的用户名,则像您所说的查询应该起作用。

make sure $_SESSION['MM_Username'] is in single quotes when you write the query. 在编写查询时,请确保$ _SESSION ['MM_Username']用单引号引起来。

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. 请注意,使用mysql_real_escape_string清理所有不需要的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在数据库中查找与用户在php中输入的内容最接近的数字匹配 - Finding the nearest numeric match in a database to what a user has inputted in php mysql和php-根据登录的用户从数据库中检索数据 - mysql and php - Retrieving data from database based on user logged in PHP / MYSQL回显从数据库表中登录用户数据 - PHP/MYSQL echo logged in user's data from database table 如何从已输入的数据库中获取时间和数据? 在 PHP 中 - how to get time & data from a database that has been input ?? in PHP PHP / MYSQL:记录用户未定义的可选数据并进行搜索优化的最佳方法是什么? - PHP/MYSQL: What should the best way to record any undefined optionals data from the user and optimized to search? 如何从mysql数据库中获取刚刚输入的表单数据的ID - How to get id from mysql database for just inputted form data 从 mysql 数据库生成和打印数据的最佳方法是什么 - What is the best way to generate & print out data from mysql database 从具有不同数据库的其他子域获取数据的最佳方法是什么? - What is the best way to get data from other subdomain with different database? 从mysql获取数据,具体取决于用户的操作 - Get data from mysql depending on what the user has done 使用PHP和MySQL从数据库中检索登录的用户信息时出现问题 - Trouble retrieving logged in user info from database with PHP and mySQL
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM