如何让多个用户访问后端并保存数据? [关闭]

I'm hoping someone can help explain this process in layman's terms, since I'm still "new" and learning.

I've built a basic content management system with a backend, and I'm trying to create a system where dozens of users can access a service, save data to their account, and recall that data at a later time if they choose.

Thus far I've got the login, registration, and forms (to save the data) complete. I'm just at a point where I don't know how to save this data in MySQL (using PHP by the way) so that dozens of users can all save data vs. just one.

Example being: Dozens of users access WordPress and can create posts, while not being able to see the other users posts on their account.

I understand how to setup one account to save data, just not multiple.

Any advice would be greatly appreciated.

P.S. If anyone has any guides/tutorials/recommended articles to read, I'd be incredibly grateful!

I think you are missing a fairly important part in how PHP works.

Each separate user uses a different instance of your application. For example, if I enter and login into the application, and you do the same, we will have (for example), the variable $_SESSION set, but I will have $_SESSION['idUser'] = 3, and you will have $_SESSION['idUser'] = 5. They will not know of each others existence.

So basically, you need to think your application for a single user, with the appropriate restrictions. Meaning that, for example, if you want to create the edit profile page, you would use $idUser = $_SESSION['idUser'] in your SQL queries to select/update/insert the appropriate information.

Here's a sample query:

// view users profile page
$idUser = intval($_SESSION['idUser']);
$query = "SELECT * FROM `users` WHERE id = {$idUser}";

// edit profile checks/database update
$idUser = intval($_SESSION['idUser']);
$userData = $_POST['user']; // let's say all your inputs have a name="user[...]"
// !!! validation for the user data !!!
$query = "UPDATE `users` SET col1='{$userData[col1]}', col2='{$userData[col2]}' WHERE id = {$idUser}";

Hope this helps, let me know if you need further clarifications.

PS: Don't forget to properly escape your data before using it in SQL queries, and use either mysqli or PDO extensions (do NOT use mysql, since it is deprecated, and will be removed in a future version of PHP).