Page 1 of 1

simple hit counter will not show values

Posted: Thu Feb 12, 2004 9:08 am
by billspeg
hi this simple hit counter will not show values and be assured the database does exist with the correct permissions and the table exist as well as the data which starts at 1. please any advice!

<?
$dbconnect= mysql_pconnect("xxxxxxxx", "xxxxx", "xxxxxxxx")or die(mysql_error());
mysql_select_db("counter", $dbconnect) or die(mysql_error());
$query = "Update countertable SET count = 'count + 1' WHERE 'PHP_SELF'";
mysql_query($query)or die(mysql_error());
$queryfrom = "SELECT count from countertable";
$row=mysql_query($queryfrom) or die(mysql_error());
mysql_fetch_row($row);
$count2 = $row['count'];
echo "You are visitor #$count2";
mysql_close($dbconnect);

?>

Solved this hit counter works

Posted: Fri Feb 13, 2004 11:18 pm
by billspeg
<?
$db = mysql_connect("xxxxxxxx", "xxxxxxx", "xxxxxxx");
mysql_select_db("hitcounter", $db);
mysql_query("UPDATE hits SET counter=counter+1 WHERE page = 'PHP_SELF'", $db);
if (mysql_affected_rows($db) < 1) {
$result = mysql_query("INSERT INTO hits VALUES ('PHP_SELF', 1)", $db);
}
$result = mysql_query("SELECT counter FROM hits",$db);
$resultcount = mysql_result($result, 0, 'counter');


echo "You are visitor # &nbsp; $resultcount";
mysql_close($db);
?>

the database was simple once i had direction
db = hitcounter
table = hits
page varchar 30 not null primary key
counter int unsigned

Posted: Fri Feb 13, 2004 11:28 pm
by Illusionist
try doing this jsut to make sure your query is correct:

Code: Select all

$sql = "UPDATE hits SET counter=counter+1 WHERE page = 'PHP_SELF'";
echo $sql;
and i'm not 100% positive, but i think it should be $_SERVER['PHP_SELF'] or it might be better to use... dunno! - worth a try!