SQL table wont update.
Posted: Tue Jun 14, 2005 8:03 pm
once PageViewStats value turns to 127. It will no longer update itself in the table no matter what.
it will increase itself from 0-127 with no problem, but once it reaches 127, it wont update itself in the table no more. Any ideas?
it will increase itself from 0-127 with no problem, but once it reaches 127, it wont update itself in the table no more. Any ideas?
Code: Select all
include 'config.php';
// Connect to the database
$test = mysql_connect("e;localhost"e;,$username,$password);
if(! $test) // check if connected
die("e;Could not connect to MySQL"e;); // error message
//select database
mysql_select_db($database)
or die (("e;could not open $database: "e;.mysql_error() )); //error message
//Get Stats
$result = mysql_query( "e;SELECT * FROM Stats WHERE id='1'"e; );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
$PageViewsStats = $rowї'PageViews'] + 1;
$MidiStats = $rowї'Midis'];
$DownloadsStats = $rowї'Downloads'];
$VisitorStats = $rowї'Visitors'];
$UserOnlineStats = $rowї'UsersOnline'];
$hostname = $_SERVERї'REMOTE_ADDR'];
$result = mysql_query( "e;SELECT * FROM Visitors WHERE ip='$hostname'"e; );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
//if ip doesnt exist
if ($rowї'id'] == "e;"e;)
{
//increase Visitor Count
$VisitorStats = $VisitorStats + 1;
//add visitor IP to visitor Table
mysql_query ("e;INSERT INTO Visitors(ip) VALUES ('$hostname')"e;)
or die(mysql_error());
mysql_query ("e;UPDATE Stats SET PageViews='$PageViewsStats', Visitors='$VisitorStats' WHERE id='1'"e;) or die(mysql_error());
}
//if ip exist
else
{
//reset PageViews in Stats Table
mysql_query ("e;UPDATE Stats SET PageViews='$PageViewsStats' WHERE id='1'"e;) or die(mysql_error());
}
$themonth = date("e;m"e;);
$theyear = date("e;Y"e;);
//Stats By Month
$result = mysql_query( "e;SELECT * FROM StatsByMonth WHERE month='$themonth' AND year='$theyear'"e; );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($rowї'id'] == "e;"e;)
{
mysql_query ("e;INSERT INTO StatsByMonth(Visitors, PageViews, Downloads, month, year) VALUES ('0', '0', '0', '$themonth', '$theyear')"e;)
or die(mysql_error());
mysql_query ("e;INSERT INTO VisitorsByMonth(ip, month, year) VALUES ('$hostname', '$themonth', '$theyear')"e;)
or die(mysql_error());
$VisitorsByMonth = 1;
$PageViewsByMonth = 1;
$DownloadsByMonth = 0;
}
else
{
$VisitorsByMonth = $rowї'Visitors'];
$PageViewsByMonth = $rowї'PageViews'] + 1;
$DownloadsByMonth = $rowї'Downloads'];
$result = mysql_query( "e;SELECT * FROM VisitorsByMonth WHERE ip='$hostname' AND month='$themonth' AND year='$theyear'"e; );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($rowї'id'] == "e;"e;)
{
mysql_query ("e;INSERT INTO VisitorsByMonth(ip, month, year) VALUES ('$hostname', '$themonth', '$theyear')"e;)
or die(mysql_error());
$VisitorsByMonth = $VisitorsByMonth + 1;
}
}
mysql_query ("e;UPDATE StatsByMonth SET Visitors='$VisitorsByMonth', PageViews='$PageViewsByMonth' WHERE month='$themonth' AND year='$theyear'"e; );
$result = mysql_query( "e;SELECT * FROM HighestRecordMonth WHERE id='1'"e; );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
$HighestVisitors = $rowї'Visitors'];
$HighestPageViews = $rowї'PageViews'];
$HighestDownloads = $rowї'Downloads'];
$DoUpdate = false;
if ($VisitorsByMonth >= $HighestVisitors)
{
$HighestVisitors = $VisitorsByMonth;
$DoUpdate = false;
}
if ($PageViewsByMonth >= $HighestPageViews)
{
$HighestPageViews = $PageViewsByMonth;
$DoUpdate = false;
}
if ($DownloadsByMonth >= $HighestDownloads)
{
$HighestDownloads = $DownloadsByMonth;
$DoUpdate = false;
}
if ($DoUpdate == true)
{
print 'test';
mysql_query ("e;UPDATE HighestRecordMonth SET PageViews='$HighestPageViews', Visitors='$HighestVisitors', Downloads='$HighestDownloads' WHERE id='1'"e; );
}
//Get Users Online
$timeout = time() - 300;
$thetime = time();
mysql_query("e;DELETE FROM UsersOnline WHERE Whenn < $timeout"e;);
$result = mysql_query( "e;SELECT * FROM UsersOnline WHERE ip='$hostname'"e; );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($rowї'id'] == "e;"e;)
{
mysql_query ("e;INSERT INTO UsersOnline(ip, Whenn) VALUES ('$hostname', '$thetime')"e;)
or die(mysql_error());
}
else
{
mysql_query ("e;UPDATE UsersOnline SET whenn='$thetime' WHERE ip='$hostname'"e; );
}
$result = mysql_query("e;SELECT * FROM UsersOnline"e;);
$NumUsersOnline = mysql_num_rows($result);
if ($NumUsersOnline > $UserOnlineStats)
{
$UserOnlineStats = $NumUsersOnline;
mysql_query ("e;UPDATE Stats SET UsersOnline='$UserOnlineStats' WHERE id='1'"e;);
}