TheBatmanOfPHP
23 Oct 2009, 10:15 AM
I know that there's free analytics software out there but i want to build my own but i am stuck at the stat. Here my INSERT is not working. I am using geoip.inc and groip.dat that i downloaded the official site.
index.php***************************
<html>
<head>
<title>MyAnalytics</title>
</head>
<body>
<?php
$id= rand(1,5);
include 'geoip.php';
?>
<div align="center">
<h1>this is a web page</h1>
</div>
</body>
</html
geoip.php*******************************
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
$today = date("Ymd");
$page="page" . $id;
include("geoip.inc");
$handle = geoip_open("GeoIP.dat", GEOIP_STANDARD);
$country=geoip_country_name_by_addr($handle, $ip);
geoip_close($handle);
include 'config.inc.php';
$connection = mysql_connect("$host", "$user", "$password");
if (!$connection) {die ("data connection failed!" . mysql_error ());}
$db_select = mysql_select_db("$database",$connection);
if(!$db_select) {die ("database selection failed!" . mysql_error());}
$result = mysql_query("SELECT * FROM $table2 WHERE date=$today AND ipadder=INET_ATON('$ip')" , $connection);
if (isset($result)) {
$row = mysql_fetch_array($result);
$id1=$row[$page];
if (isset($id1)) {
$id1++;
mysql_query("UPDATE $table2 SET $page = '$id1' WHERE date=$today AND ipadder=INET_ATON('$ip')", $connection) or die("UPDATE failed: " . mysql_error());
echo "UPDATE, id=" . $id . ", id1=" . $id1;;
};} else {
mysql_query("INSERT INTO $table2 ($id, ipadder, country, date) VALUES ('1', INET_ATON('$ip') ,'$country', '$today')", $connection) or die("INSERT failed: " . mysql_error());
}
mysql_close($connection);
echo "INSERT, id=" . $id;
}
?>
The INSERT is not working.
Please help!
index.php***************************
<html>
<head>
<title>MyAnalytics</title>
</head>
<body>
<?php
$id= rand(1,5);
include 'geoip.php';
?>
<div align="center">
<h1>this is a web page</h1>
</div>
</body>
</html
geoip.php*******************************
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
$today = date("Ymd");
$page="page" . $id;
include("geoip.inc");
$handle = geoip_open("GeoIP.dat", GEOIP_STANDARD);
$country=geoip_country_name_by_addr($handle, $ip);
geoip_close($handle);
include 'config.inc.php';
$connection = mysql_connect("$host", "$user", "$password");
if (!$connection) {die ("data connection failed!" . mysql_error ());}
$db_select = mysql_select_db("$database",$connection);
if(!$db_select) {die ("database selection failed!" . mysql_error());}
$result = mysql_query("SELECT * FROM $table2 WHERE date=$today AND ipadder=INET_ATON('$ip')" , $connection);
if (isset($result)) {
$row = mysql_fetch_array($result);
$id1=$row[$page];
if (isset($id1)) {
$id1++;
mysql_query("UPDATE $table2 SET $page = '$id1' WHERE date=$today AND ipadder=INET_ATON('$ip')", $connection) or die("UPDATE failed: " . mysql_error());
echo "UPDATE, id=" . $id . ", id1=" . $id1;;
};} else {
mysql_query("INSERT INTO $table2 ($id, ipadder, country, date) VALUES ('1', INET_ATON('$ip') ,'$country', '$today')", $connection) or die("INSERT failed: " . mysql_error());
}
mysql_close($connection);
echo "INSERT, id=" . $id;
}
?>
The INSERT is not working.
Please help!