sql error
Posted: Sun Apr 23, 2006 1:32 pm
error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mounted-storage/home16a/sub002/sc18478-RGIJ/www.po2upload.com/update_stats.php on line 45
error on line 45
the rest of the code works up till line 45
error on line 45
the rest of the code works up till line 45
Code: Select all
//Stats By Month
$result = mysql_query( "SELECT * FROM po2StatsByMonth WHERE month='$themonth' AND year='$theyear'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $rowCode: Select all
<?php
require_once 'config.php';
/////Visitors a month. Page views per month
////////////
///////////
/////////
////////////
///////////
$hostname = $_SERVER['REMOTE_ADDR'];
//Get Stats
$result = mysql_query( "SELECT * FROM po2_stats WHERE id='1'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
//increase page views
$PageViewsStats = $row['PageViews'] + 1;
//check if visitor allready visited.
$result = mysql_query( "SELECT * FROM po2_visitors WHERE ip='$hostname'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
//if ip doesnt exist
if ($row['id'] == "")
{
//increase Visitor Count
$VisitorStats = $VisitorStats + 1;
//add visitor IP to visitor Table
mysql_query ("INSERT INTO po2_visitors(ip) VALUES ('$hostname')")
or die(mysql_error());
}
//reset PageViews in Stats Table
mysql_query ("UPDATE po2_stats SET PageViews='$PageViewsStats' WHERE id='1'") or die(mysql_error());
$themonth = date("m");
$theyear = date("Y");
$theday = date("d");
//Stats By Month
$result = mysql_query( "SELECT * FROM po2StatsByMonth WHERE month='$themonth' AND year='$theyear'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($row['id'] == "")
{
mysql_query ("INSERT INTO po2_StatsByMonth(Visitors, PageViews, Downloads, month, year) VALUES ('0', '0', '0', '$themonth', '$theyear')")
or die(mysql_error());
mysql_query ("INSERT INTO po2_VisitorsByMonth(ip, month, year) VALUES ('$hostname', '$themonth', '$theyear')")
or die(mysql_error());
$VisitorsByMonth = 1;
$PageViewsByMonth = 1;
}
else
{
$VisitorsByMonth = $row['Visitors'];
$PageViewsByMonth = $row['PageViews'] + 1;
$result = mysql_query( "SELECT * FROM po2_VisitorsByMonth WHERE ip='$hostname' AND month='$themonth' AND year='$theyear'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($row['id'] == "")
{
mysql_query ("INSERT INTO po2_VisitorsByMonth(ip, month, year) VALUES ('$hostname', '$themonth', '$theyear')")
or die(mysql_error());
$VisitorsByMonth = $VisitorsByMonth + 1;
}
}
mysql_query ("UPDATE po2_StatsByMonth SET Visitors='$VisitorsByMonth', PageViews='$PageViewsByMonth' WHERE month='$themonth' AND year='$theyear'" );
/////////////////////
////////////////
////////Stats by day, visitors and page views.
//Stats By dat
$result = mysql_query( "SELECT * FROM po2_StatsByDay WHERE month='$themonth' AND year='$theyear' AND day='$theday'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($row['id'] == "")
{
mysql_query ("INSERT INTO po2_StatsByDay(Visitors, PageViews, month, year, day) VALUES ('0', '0', '$themonth', '$theyear','$theday')")
or die(mysql_error());
mysql_query ("INSERT INTO po2_VisitorsByDay(ip, month, year, day) VALUES ('$hostname', '$themonth', '$theyear','$theday')")
or die(mysql_error());
$VisitorsByDay = 1;
$PageViewsByDay = 1;
}
else
{
$VisitorsByDay = $row['Visitors'];
$PageViewsByDay = $row['PageViews'] + 1;
$result = mysql_query( "SELECT * FROM po2_VisitorsByDay WHERE ip='$hostname' AND month='$themonth' AND year='$theyear' AND day='$theday'" );//
$row=mysql_fetch_array($result); //Store Record Of Data in $row
if ($row['id'] == "")
{
mysql_query ("INSERT INTO po2_VisitorsByDay(ip, month, year, day) VALUES ('$hostname', '$themonth', '$theyear', '$theday')")
or die(mysql_error());
$VisitorsByDay = $VisitorsByDay + 1;
}
}
mysql_query ("UPDATE po2_StatsByDay SET Visitors='$VisitorsByDay', PageViews='$PageViewsByDay' WHERE month='$themonth' AND year='$theyear' AND day='$theday'" );
?>