Ok guys i've got a really strange problem here for you.
Below is the code for the main index of the site i'm working on.
//----------------------
//start the script timer
//----------------------
$script_start = explode(" ", microtime());
$script_start = (float)$script_start[1] + (float)$script_start[0];
//---------------------------
//load the required files
//---------------------------
require ('config.php');
require ('cache/adminmenu.php');
require ('skins/skin.php');
require ('skins/menuskin.php');
require ('admin/adminmenuskin.php');
//-------------------------------------------------
// Connecting to mysql database, selecting database
//-------------------------------------------------
$db_link = @mysql_connect( $config['db_host'], $config['db_username'], $config['db_password'] )
or die( skin_mysql_error( '<b>Could not connect to database!</b> ' ) );
//-----------------------------------
// get general settings from database
//-----------------------------------
@mysql_select_db( $config['db_name'] )
or die( skin_mysql_error( '<b>Could not select database!</b><br /><br />' ) );
$result = @mysql_query( "SELECT * FROM site_general" )
or die( skin_mysql_error( '<b>Database Query failed! - general settings</b> ' ) );
$general = mysql_fetch_array( $result, MYSQL_ASSOC );
mysql_free_result( $result );
//-------------------------------------------------------------------
// assign general settings data into more useable variable structures
//-------------------------------------------------------------------
require ('variables.php');
//-----------------------------------------------------
// update the sig image according to to what hour it is
//-----------------------------------------------------
require ('modules/sigrotator.php');
//-------------------
// Are we logged in?
//-------------------
if ( isset( $_COOKIE[$settings->cookie_name.'_id'] ) && isset( $_COOKIE[$settings->cookie_name.'_pw'] ) && isset( $_COOKIE[$settings->cookie_name.'_username'] ) )
{
$result = @mysql_query( "SELECT * FROM site_admins WHERE admin_id = '".$_COOKIE[$settings->cookie_name.'_id']."'" )
or die( skin_mysql_error( '<b>Database Query failed!</b> ' ) );
$login = mysql_fetch_array( $result, MYSQL_ASSOC );
if ( $_COOKIE[$settings->cookie_name.'_pw'] === $login['admin_password'] && $_COOKIE[$settings->cookie_name.'_username'] === $login['admin_username'] )
{
$logged_in = TRUE;
}
else
{
$logged_in = FALSE;
}
}
else
{
$logged_in = FALSE;
}
//--------------
// parse the url
//--------------
$url = explode( '/', str_replace( $settings->domain_offset.'/', '', $_SERVER['REQUEST_URI'] ) );
$output->page_id = $url[1];
$output->page_name = $url[2];
//-------------------------------------------------------------
// Generate the Admin Menu array (if admin is viewing the page)
//-------------------------------------------------------------
if ($logged_in)
{
$adminmenuerror = TRUE;
while( $adminmenuitem = each( $adminmenu_array ) )
{
$adminmenu[] = array( "name" => $adminmenuitem['key'], "link" => $adminmenuitem['value'] );
$adminmenuerror = FALSE;
}
}
//----------------------------
// get page data from database
//----------------------------
echo $output->page_id;
$result = @mysql_query( "SELECT * FROM site_pages WHERE page_id='$output->page_id' " )
or die( skin_mysql_error( '<b>Query failed: - page data</b> ') );
$data = mysql_fetch_array( $result, MYSQL_ASSOC );
mysql_free_result( $result );
$count = $data['page_views'];
//------------
//start output
//------------
if ( $output->page_id == '' )
{
echo skin_header().
skin_homepage();
}
elseif ( $output->page_id == "contact" )
{
echo skin_header().
skin_content_header().
skin_contactpage();
}
elseif ( $data == '' )
{
echo skin_header().
skin_error_404();
}
else
{
$output->page_name = $data['page_name'];
$output->page_title = $data['page_title'];
$output->page_keywords = $data['page_keywords'];
$output->page_descrip = $data['page_descrip'];
$output->page_views = $data['page_views'];
$output->page_content = $data['page_content'];
echo skin_header().
skin_content_header();
}
//------------------------------------------------
// Updating hitcounter for currently viewed page
//------------------------------------------------
echo $count++;
echo $count;
$query = "UPDATE site_pages SET page_views=$count WHERE page_id='$output->page_id'";
mysql_query( $query )
or die( skin_mysql_error( '<b>Database Query failed! - hit counter</b> '.mysql_error() ) );
// ------------
// Output Menu
// ------------
echo skin_menu_wrapper();
//-----------------------------------------------------
// Output the admin menu (if admin is viewing the page)
//-----------------------------------------------------
if ( $logged_in )
{
echo skin_adminmenustart();
if ( $adminmenuerror )
{
echo "No admin links";
}
else
{
foreach ( $adminmenu as $adminmenurow )
{
echo skin_adminmenu_item( $adminmenurow['name'], $adminmenurow['link'] );
}
echo skin_adminmenu_logout().skin_adminmenu_end();
}
}
echo skin_start_footer();
//-------------------------------------------------
// Freeing up database results and close connection
//-------------------------------------------------
mysql_close( $db_link );
//-----------------------------------------
//stop timer, process the result and output
//-----------------------------------------
$script_end = explode( " ", microtime() );
$script_end = (float)$script_end[1] + (float)$script_end[0];
$output->script_timer = $script_end - $script_start;
$output->script_timer = round($output->script_timer, 3);
if ( $output->script_timer == 0 )
{
$output->script_timer = 0.001;
echo skin_timer_output();
}
else
{
echo skin_timer_output();
}
echo skin_end_footer();
At the moment i'm using search engine friendly url's ( http://www.blah.com/index/1/page_name.htm ).
Now the problem is, the data for $count isn't being entered into the database correctly.
If $count is something like 40, then the value that get's stored in the database will be +7. So 47. This basically means it adds 7 to my hitcount everytime.
Here's the strange part. If i return the url parsing style back to normal php queires ( e.g. http://www.blah.com/index.php?page=1 ) then the data get's stored as it should.
I can't figure out how this difference would cause mysql to add 7 to the count value.
Any help will be appreciated.