Results 1 to 6 of 6

Thread: Hit Counter Help

  1. #1
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Question Hit Counter Help

    Hey All,

    I'm making a MySQL/PHP hit counter, to "sniff" the browser and calculate how many times each browser is hitting my site.

    Here's what I have:
    Code:
    	$bowser_sniff == $_SERVER['HTTP_USER_AGENT'];
    	$db = mysql_connect("localhost", "user", "passwd");
    	mysql_select_db("hits_db",$db);
    	mysql_query("UPDATE hits SET counter=counter+1 WHERE browser = '$bowser_sniff'",$db);
    	if (mysql_affected_rows($db) < 1) { $result = mysql_query("INSERT INTO hits VALUES ('$bowser_sniff', 1)", $db); }
    I've got the hits updating, but the browser isn't being added, I just get a blank entry.

    And help would be appreciated.

    Edit: I'm almost certain it's something to do with the variable in the mysql_query


    Thanks
    X96
    Last edited by X96 Web Design; 05-24-2009 at 04:01 PM. Reason: fixeded me grammr
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    This line:

    Code:
    	$bowser_sniff == $_SERVER['HTTP_USER_AGENT'];
    remove one of the = and it should be good.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    X96 Web Design (05-24-2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Thanks! It works perfectly.

    / X96 \
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  5. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Just a quick thing of no real importance but you have "bowser_sniff" instead of "browser_sniff"

  6. #5
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    I know... I did that on purpose...

    // X \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  7. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Haha xD

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •