This topic is locked

Decrease an integer field by 1 after successful login - what is the php?

8/19/2026 20:07:09
PHPRunner Tips and Tricks
J
jcutts author

I have a table called mcat_form, which holds data for each user of my project. One of the fields is "counter". Counter is initially set to 25 but I want it reduced by 1 every time the user successfully logs in.

What would the php code be to do this?

I assume that I am already logged in to the mySQL, since that is built into the project. I understand that the code should go in Events, under Log In Page/After successful log in.

Thanks anybody!

C
Chris Whitehead 8/20/2026

If you want a simple query.

$query = "UPDATE mcat_form SET counter=counter-1 WHERE user_id=" . $_SESSION['UserData']['id'];

Ideally you'll want to put in some other checks so the counter can't go below 0