Hi folks
Everything works on the result page, but saving to database, for some reason I get these errors on the result page, yet I know, all the database login info is correct.
Below is my complete results page
and below is my settings from speedtest.cfg
Everything works on the result page, but saving to database, for some reason I get these errors on the result page, yet I know, all the database login info is correct.
PHP Code:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'XXXXX@'localhost' (using password: YES) in /home/.../results.php on line 16
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/.../results.php on line 17
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/.../results.php on line 31
PHP Code:
// Complete results.php
require("common.php");
ReadConfig("speedtest.cfg");
## Save the results of this test to the database, if enabled
if($config->{'database'}->{'enable'}) {
$ip_matches = $config->{'database'}->{'ip_matches'};
if( (! $ip_matches) || ($ip_matches && preg_match("/$ip_matches/",$_SERVER['REMOTE_ADDR'])) ) {
Debug("Saving to database");
$dbh = mysql_connect(
$config->{'database'}->{'host'},
$config->{'database'}->{'user'},
$config->{'database'}->{'password'}
);
$dbs = mysql_select_db( $config->{'database'}->{'database'}, $dbh);
$table = $config->{'database'}->{'table'};
$ip = $_SERVER['REMOTE_ADDR'];
$upspeed = addslashes($_GET['upspeed']);
$downspeed = addslashes($_GET['downspeed']);
$sql = "
INSERT INTO `$table`
SET
`ip_string` = '$ip',
`ip` = INET_ATON('$ip'),
`timestamp` = NOW(),
`upspeed` = '$upspeed',
`downspeed` = '$downspeed'
";
mysql_query($sql,$dbh);
}
}
PHP Code:
// this function located in common.php
function ReadConfig($config_file) {
global $config;
$lines = file($config_file);
foreach ($lines as $line_num => $line) {
$line = rtrim(preg_replace("/#.*/","",$line));
if(preg_match("/\[.*\]/", $line, $parts)) {
$section = $parts[0];
$section = preg_replace("/[\[\]]/","",$section);
} elseif (preg_match("/=/",$line)) {
list($var,$value) = split('=',$line);
$var = preg_replace('/ $/','',$var);
$value = preg_replace('/^ +/','',$value);
$config->{$section}->{$var} = $value;
}
}
}
Code:
## Set to 1 to enable enable = 1 host = localhost database = testdb user = testuser password = testpass table = testtable ## Regular expression to match to save results to the database ip_matches =
Comment