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);
?>
simple hit counter will not show values
Moderator: General Moderators
Solved this hit counter works
<?
$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 # $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
$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 # $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
try doing this jsut to make sure your query is correct:
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!
Code: Select all
$sql = "UPDATE hits SET counter=counter+1 WHERE page = 'PHP_SELF'";
echo $sql;