SQL table wont update.

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!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

SQL table wont update.

Post by psychotomus »

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?

Code: Select all

include 'config.php';
// Connect to the database
$test = mysql_connect(&quote;localhost&quote;,$username,$password); 
if(! $test) // check if connected
die(&quote;Could not connect to MySQL&quote;); // error message

//select database
mysql_select_db($database)
or die ((&quote;could not open $database: &quote;.mysql_error() )); //error  message


//Get Stats
$result = mysql_query( &quote;SELECT * FROM Stats WHERE id='1'&quote; );//
$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( &quote;SELECT * FROM Visitors WHERE ip='$hostname'&quote; );//
$row=mysql_fetch_array($result);	//Store Record Of Data in $row 

//if ip doesnt exist
if ($rowї'id'] == &quote;&quote;)
{
//increase Visitor Count
$VisitorStats = $VisitorStats + 1;
//add visitor IP to visitor Table
mysql_query (&quote;INSERT INTO Visitors(ip) VALUES ('$hostname')&quote;) 
		or die(mysql_error());
mysql_query (&quote;UPDATE Stats SET PageViews='$PageViewsStats', Visitors='$VisitorStats' WHERE id='1'&quote;) or die(mysql_error());

}
//if ip exist
else
{
//reset PageViews in Stats Table
mysql_query (&quote;UPDATE Stats SET PageViews='$PageViewsStats' WHERE id='1'&quote;) or die(mysql_error());

}

$themonth = date(&quote;m&quote;);
$theyear = date(&quote;Y&quote;);

//Stats By Month
$result = mysql_query( &quote;SELECT * FROM StatsByMonth WHERE month='$themonth' AND year='$theyear'&quote; );//
$row=mysql_fetch_array($result);	//Store Record Of Data in $row 


if ($rowї'id'] == &quote;&quote;)
{
mysql_query (&quote;INSERT INTO StatsByMonth(Visitors, PageViews, Downloads, month, year) VALUES ('0', '0', '0', '$themonth', '$theyear')&quote;) 
		or die(mysql_error());

mysql_query (&quote;INSERT INTO VisitorsByMonth(ip, month, year) VALUES ('$hostname', '$themonth', '$theyear')&quote;) 
		or die(mysql_error());

$VisitorsByMonth = 1;
$PageViewsByMonth = 1;
$DownloadsByMonth = 0;
}
else
{
$VisitorsByMonth = $rowї'Visitors'];
$PageViewsByMonth = $rowї'PageViews'] + 1;
$DownloadsByMonth = $rowї'Downloads'];

	$result = mysql_query( &quote;SELECT * FROM VisitorsByMonth WHERE ip='$hostname' AND month='$themonth' AND year='$theyear'&quote; );//
	$row=mysql_fetch_array($result);	//Store Record Of Data in $row 

	if ($rowї'id'] == &quote;&quote;)
	{
		mysql_query (&quote;INSERT INTO VisitorsByMonth(ip, month, year) VALUES ('$hostname', '$themonth', '$theyear')&quote;) 
			or die(mysql_error());

		$VisitorsByMonth = $VisitorsByMonth + 1;
	}
}

mysql_query (&quote;UPDATE StatsByMonth SET Visitors='$VisitorsByMonth', PageViews='$PageViewsByMonth' WHERE month='$themonth' AND year='$theyear'&quote; );


$result = mysql_query( &quote;SELECT * FROM HighestRecordMonth WHERE id='1'&quote; );//
$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 (&quote;UPDATE HighestRecordMonth SET PageViews='$HighestPageViews', Visitors='$HighestVisitors', Downloads='$HighestDownloads' WHERE id='1'&quote; );
}


//Get Users Online
$timeout = time() - 300;
$thetime = time();
mysql_query(&quote;DELETE FROM UsersOnline WHERE Whenn < $timeout&quote;); 

$result = mysql_query( &quote;SELECT * FROM UsersOnline WHERE ip='$hostname'&quote; );//
$row=mysql_fetch_array($result);	//Store Record Of Data in $row 

if ($row&#1111;'id'] == &quote;&quote;)
{
			mysql_query (&quote;INSERT INTO UsersOnline(ip, Whenn) VALUES ('$hostname', '$thetime')&quote;) 
			or die(mysql_error());
}
else
{
	mysql_query (&quote;UPDATE UsersOnline SET whenn='$thetime' WHERE ip='$hostname'&quote; );
}

	$result = mysql_query(&quote;SELECT * FROM UsersOnline&quote;);
	$NumUsersOnline = mysql_num_rows($result);


if ($NumUsersOnline > $UserOnlineStats)
{
$UserOnlineStats = $NumUsersOnline;
mysql_query (&quote;UPDATE Stats SET UsersOnline='$UserOnlineStats' WHERE id='1'&quote;);
}
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

First of all, use [ php ] tags for php code (good try though).

Can we see the schematics of your table?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I've got a feeling you are using TINYINT or something like that as the column type.. Might want to ALTER that to INT
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

worked with INT.
Post Reply