I have a database with the fields username, password and sessions. Each user has a certain amount of sessions and I have setup my site to display how many sessions that user has left when he logs in.
How do I get it so that when he logs in, the sessions field under his id gets decreased by 1, so then his amount of sessions will be 1 less when he views it on the next page?
This would need like an update record function that occurs at the same time when the user clicks login, only if the login details are correct though.
What code would I need to do this? Any ideas? Thanks in advance.
How to decrease a database field by 1 when user logs on????
Moderator: General Moderators
SQL:
Assuming your user table is called "users", your sessions column "sessions" and user id is "id".
Of course $userid would either be replaced with a bind variable or escaped appropriately beforehand
Code: Select all
UPDATE users SET sessions = sessions - 1 WHERE id = $useridOf course $userid would either be replaced with a bind variable or escaped appropriately beforehand