I have a table which logs IP addresses (index) and time stamp after form submission which cannot be resubmitted within, say, a minute. I've got the logic working for INSERT ON DUPLICATE KEY UPDATE which inserts a row if there's no IP in the table or updates the row if the IP is already there and it will keep updating it. What I need is it should:
- Insert row if no IP
- Update row if IP but now() < timestamp
- Insert new row if now() > timestamp
This is what I've got so far:
$q = 'INSERT INTO btTable (ip, timestamp)
VALUES(INET_ATON (?),?)
ON DUPLICATE KEY UPDATE timestamp = ?';
$v = [$this->host_ip, date('YmdHi'), date('YmdHi')];
$db->executeQuery($q, $v);
Thank you.