Basically, I have a table to log when users login and what's their latest IP.
To prevent duplicates, i use the following method: screenshot
This works fine, to a certain degree. Sometimes, or actually plenty of times you can spam request it to log twice, or even more than twice. The requests are sent really rapidly, so this does not work very well.
I assume one way to speed it up, would be to have a simple SQL Query to search to perform this:
Search for the username... If it exists, update IP. If it does not exist, insert new column.
But, how I would do this? I have no idea. Most of the methods are using "ON DUPLICATE KEY" which does not work with text/blob.
Any help is greatly appreciated.
Code: http://pastebin.com/xuFmgFp0
$result = $conpdo->prepare("SELECT * FROM `logs` WHERE `username` LIKE :username");
$result->execute(array(':username' => $_GET['username']));
$info = $result->fetch(PDO::FETCH_ASSOC);
if(empty($info))
{
$result = $conpdo->prepare("INSERT INTO `logs` (`id`, `ip`, `username`, `last_update`) VALUES (NULL, :ip, :username, '0000-00-00 00:00:00');");
$result->execute(array(':username' => $_GET['username'], ':ip' => $_GET['ip']));
}
else
{
$result = $conpdo->prepare("UPDATE `logs` SET `ip` = :ip WHERE `logs`.`id` = :id");
$result->execute(array(':ip' => $_GET['ip'], ':id' => $info['id']));
}