upvote upvote - 1 year ago 84
SQL Question

mysql UPDATE function with DATE_ADD() function

Table structure:

enter image description here

I encounter

function recently while I am searching for a process of how to make a warning in multiple fail login attempts in php. I want to learn how to use this with
mysql UPDATE
function where, first, it sets the
current date
and then it will
add 15 minutes
(interval) so that, the user can't login in the next 15 mins.


example: if the user failed to login 3 times. it will update the user's account that, he/she can log on the next 15 minutues.

this is something code that I think but not working to me

$sql = "UPDATE {$users} SET {$reLoginDate} = DATE_ADD({$reLoginDate}, 15 INTERVAL MINUTE) WHERE {$user} = {$username}";

is set on current time and will
15 minutues in advance.

Here is the image of my table: 2nd update:
table screen shot

Answer Source

It's simple thing, try this:

$sql = "UPDATE users
        SET reLoginDate = DATE_ADD(reLoginDate, INTERVAL 15 MINUTE)
        WHERE user = '$username'";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download