All the small snippet of code below is supposed to do is take your ip address and query the db for any matches. If a match is found, it then checks to see if the match was created the same day. If so it increases the visits by 1, if not it inserts your ip back into the db for that day’s date.
For some odd reason its not working, nor is it giving me any errors.
[php]// DB Query
$results = mysql_query(“SELECT ip
FROM visitors
WHERE ip
= ‘$IP’”);
// IP was not found
if(empty($results))
{
// Put IP in DB
mysql_query(“INSERT INTO visitors
(id
, ip
, date
, visits
) VALUES (NULL, ‘$IP’, ‘$DATE’, ‘1’)”);
} else
{
// Was IP visit on today’s date?
$results = mysql_query(“SELECT ip
FROM visitors
WHERE ip
= ‘$IP’ AND date
= ‘$DATE’”);
// IP not found for today’s date.
if(empty($results))
{
mysql_query(“INSERT INTO visitors
(id
, ip
, date
, visits
) VALUES (NULL, ‘$IP’, ‘$DATE’, ‘1’)”);
} else
{
mysql_query(“UPDATE visitors
SET visits
= ‘200’ WHERE ip
= ‘$IP’ AND date
= ‘$DATE’”);
}
}[/php]
The connection to the DB are working it should but that still doesn’t explain why nothing is happening. I’ve tried inserting the IP into the DB manually to see if it would update the visits count, and it didn’t. I tried emptying the DB to see if it would insert the IP and it still did nothing.
What’s weird is if I put a “echo” in the very last else statement where it’s supposed to be updating the counts of visits, it displays the echo, so I know it is executing the code all the way to the last if-else statement, but it still isn’t making any updates or changes in the DB like it’s supposed to be doing.