Skip to content
Advertisement

How to remove data from an SQL row but not delete it PHP

I am working on a login system that will log a users IP for a day after they login and clear it after one day. I know you can delete rows but i don’t know how to clear a row. The table i have is this.

+----------+----------+---------+
| Username | Password |   IP    |
+----------+----------+---------+
| TEST     | TEST     | EXAMPLE |
+----------+----------+---------+

What i want to do is in the IP row i want to be able to clear the data in that row after one day of it being entered. Is there a way to do this in PHP?

Advertisement

Answer

You can easily add one column in your table named last_login_date and use a cron job per hour or minutes (that’s on you) and check if last_login_date is more than 24 hours then empty IP. I hope it helps.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement