View Single Post
  #1 (permalink)  
Old 05-09-2008,
Keith Keith is offline
Junior Member
 
Join Date: May 2008
Posts: 3
Default Inserting rows twice

So I modified logger.php so that it inserts the data into a MySQL database instead of the log file. Its all working fine except its inserting two rows with identical information and timestamps except for the downloadSpeed and uploadSpeed columns. One row has 0 and 0 while the other row has the actual speeds.

If I navigate to logger.php manually, it adds the single row properly (with 0 and 0 for the up/down speeds because the test wasn't run and $_POST is empty) but if I perform the speed test, it behaves as noted above.

Here is the modified logger.php file:

Code:
<!-- echo -->
<!-- Do not remove the echo comment above or speeds will not be recorded -->
<?
	if (isset($HTTP_POST_VARS['testspeeds'])) 
	{ 
		$testspeeds =  $HTTP_POST_VARS['testspeeds'];
		$speeds = explode("\t", $testspeeds);
		$info['downloadSpeed'] = $speeds[0];
		$info['uploadSpeed'] = $speeds[1];
	} else {
		$info['downloadSpeed'] = 0;
		$info['uploadSpeed'] = 0;
	}
	
	if (isset($_SERVER['REMOTE_ADDR'])) 
	{ 
		$info['ip'] = $_SERVER['REMOTE_ADDR'];
	} else {
		$info['ip'] =  getenv('REMOTE_ADDR');
	}
	
	if (isset($_SERVER['HTTP_USER_AGENT'])) 
	{ 
		$info['browser'] = $_SERVER['HTTP_USER_AGENT'];
	} else {
		$info['browser'] = "";
	}
	
	if (isset($_SERVER['PHP_SELF'])) 
	{ 
		$info['page'] = $_SERVER['PHP_SELF'];
	} else {
		$info['page'] = "";
	}
	
	if (isset($_SERVER['HTTP_REFERRER'])) 
	{ 
		$info['referrer'] = $_SERVER['HTTP_REFERRER'];
	} else {
		$info['referrer'] = "";
	}
	
	require('PATHTOFILEWITHUSERNAMES');
	require_once('../include/mySQL.php');
	$db = new mySQL($logsUser, $logsPass);
	$x = 0;
	$cols = '(';
	$vals = '(';
	foreach ($info as $k => $v)
	{
		$x++;
		$last = ($x == count($info)) ? true : false;
		
		$cols .= "`{$k}`";
		$vals .= "'{$v}'";
		
		if (!$last)
		{
			$cols .= ', ';
			$vals .= ', ';
		}
	}
	$cols .= ')';
	$vals .= ')';
	
	$sql = "INSERT INTO `logs` {$cols} VALUES {$vals}";
	$db->selectDatabase('MYDATABASE');
	$db->query($sql);
	unset($db);
?>
Any insight would be greatly appreciated.
__________________
Keith

bloodninja.org
duvalltech.com
rlpspeedtest.com
Reply With Quote