How do I save last session of a persons account in MySQL

So in my databases in MySQL I have created a table to store and handle the usernames and passwords but how do I make that store the last session of the person’s account?

My code for storing user login info

CREATE TABLE `users` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(50) NOT NULL,
 `email` varchar(50) NOT NULL,
 `password` varchar(50) NOT NULL,
 `create_datetime` datetime NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4

For example
I have a div in HTML with the id of coin-count that goes up with a click of a button controlled by js. I want to store the div so that the next time that same user logs in it are the same. So something like that will be saved.

Hello!

You wouldn’t store the div, you would store only the value. For that, you would send the value to an endpoint on your back end and that endpoint would validate the data and store it on the database.

To display the value, the front end would query a different endpoint to retrieve that value and display it on the div.

You cannot use most databases from the front end, but it’s not a good idea anyway as it is insecure (specially if it’s sensitive data, like user’s emails, passwords, etc.). However, if you’re doing it for testing purposes, then you could use something like Firestore, which is a NoSQL database.

If you follow the secure way (a back end app), then you would usually create a different table to store the data. For how to structure the data, I would suggest you to study database design (the normal forms), but for a start, you could just add a new column to the existing table.

You should finish the course you’re currently on to understand how the front end should communicate with the back end and how to handle database logic :slight_smile:.