simple hit counter will not show values

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
billspeg
Forum Newbie
Posts: 7
Joined: Sun Dec 28, 2003 3:47 am

simple hit counter will not show values

Post 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);

?>
billspeg
Forum Newbie
Posts: 7
Joined: Sun Dec 28, 2003 3:47 am

Solved this hit counter works

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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!
Post Reply