PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi Guys,
Please can anyone tell me why this snippet
is not doing what is expected.
The code could store only the date but not
IP address.
Please why??
Can anyone help me??
Thanks in advanced
<?php
$ip_address = $REMOTE_ADDR;
$the_date = date("Y-m-d");
$conn = @mysql_connect("localhost","username","password") or die("cannot connect to MySQL");
@mysql_select_db("ipvisits") or die("cannot connect to the database");
@mysql_query("INSERT INTO visitorsips(ip,date) VALUES ('$ip_address','$the_date')");
mysql_close($conn);
?>
I don't get any error but the IP is not store into the db.
And my second question is to limit the IP to 1.
Because the date is recorded in every visit of the visitor which I don't want.
$count_query = mysql_query("SELECT * FROM counter");
$hits = mysql_num_rows($count_query);
$hits++;
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query("INSERT INTO counter VALUES($hits, '$ip', $time)"); // Log current IP, hit number & time
$ip address is stored as string, $time & $hits are integers