Please help a complete noob. 
I have the following problem:
User1 enters site the first time and is given gift1 at second visit gift2 and so on…
User2 enters site the first time and is given gift1 at second visit gift2 and so on…
Each user can receive each gift only 1 time.
Users are identified by IP
Db structure:
table IP_used (id, ip_address)
table gift (giftid,description)
So far I’ve managed to do this: user enters site > check in db if ip exists > if it doesn’t exist add and display 1 > else display 2
[php]<?php
$db = new PDO(
‘mysql:host=localhost;dbname=**********’,
‘’,
'’
);
$ipData = [ ‘:ip’ => $_SERVER[‘REMOTE_ADDR’] ];
$statement = $db->prepare(’
SELECT count(*) FROM IP_used
WHERE ip_address = :ip
');
$statement->execute($ipData);
if ($statement->fetchColumn() == 0 ) {
// add to list
$statement = $db->prepare(’
INSERT INTO IP_used (
ip_address
) VALUES (
:ip
)
');
$statement->execute($ipData);
// do whatever it is you are doing for first-visit
echo(1);
} else {
// subsequent visit content here
echo(2);
}
?>[/php]