Dunno if this helps. I shortened up the code a little bit as you can see. In addition, if you set a session variable to detect if the counter has already been ran, a user can't click on the refresh button all day and update your total_hits over and over. Typically, I would include the counter code in each page of the site via an include file.
Also check your mysql fields and make sure they are the right data types, if your using something like tinyint your going to run into trouble!