Mysql Hit Counter<

liunx

Guest
I have my query

CREATE TABLE hitcounter (
id int NOT NULL auto_increment,
count int NOT NULL,
PRIMARY KEY (id)
);

and i have my PHP code

<?php
$db = mysql_connect("$dbHost","$dbUser","$dbPass");
mysql_select_db($dbname,$db);

$hits = "SELECT hits FROM hitcounter";

$hits[0] ++;

echo "Hits: $hits";

close ($db);
?> and i have the error:
Fatal error: Cannot increment/decrement overloaded objects nor string offsets

now, i know the error is something to do with $hits[0] ++; but i don't know why, can anyone tell me?

tia, JoeWell, for one you don't have a column called 'hits', and you're not executing the query. Then you're trying to increase the first element of a string with one... That works in some languages I think, but it seems PHP doesn't like it. It's not what you want to do anyway eh?Further more, the function is mysql_close(), and where do you set the info for the db connection?
You will have to run an UPDATE query as well, to increase the counter.Originally posted by Rydberg
Well, for one you don't have a column called 'hits', and you're not executing the query. Then you're trying to increase the first element of a string with one... That works in some languages I think, but it seems PHP doesn't like it. It's not what you want to do anyway eh? ah, i didn't even see that :o

set the info for the database connection?

UPDATE $hits

hmm, looks like i will have to do alot more researchOriginally posted by joe2kiss set the info for the database connection?
Yeah, just wondering where you get the $dbname, $dbHost, $dbUser, $dbPass vars from.. Are you including a file with this info or..?yeah, the server info is getting included above but i didnt put the code in because it has my username ect in it
 
Back
Top