Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2004
    Location
    Harrogate, Yorkshire, UK
    Posts
    21

    Strange Mysql problem - updating integer

    I'm fairly new to mysql databases so i'm probably doing something very silly. Here's my problem.

    I'm using php to update the database. All i'm trying to do is add 1 to a hit count number and update it in the database.

    When i update, i use this query

    PHP Code:
    mysql_query"UPDATE site_pages SET page_views='$count' WHERE page_id='$output->page_id'" 
    Where $count is the updated hitcount. The problem is, for some reason when the value get's entered into the database it's been increased by 7. For example, if $count holds the value '40' it get's entered into the database as 47.

    I've done all the necessary checks to make sure that $count is indeed the correct value i want.

    Anyone got any ideas?
    Feel free to visit my sites: GTA San Andreas | My Portfolio

  2. #2
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,082

  3. #3
    Join Date
    Oct 2004
    Location
    Harrogate, Yorkshire, UK
    Posts
    21
    Ok I'll use that way instead. It does exactly the same thing though. Add's 7 on top in the database.

    My only guess is that i've set up the database/table/field wrong. The 'page_views' field is set to 'INT'
    Feel free to visit my sites: GTA San Andreas | My Portfolio

  4. #4
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,082

  5. #5
    Join Date
    Oct 2004
    Location
    Harrogate, Yorkshire, UK
    Posts
    21
    No it can't be, because before it was just a number to insert. If it was being called 7 times it would just insert the number 7 times.
    Feel free to visit my sites: GTA San Andreas | My Portfolio

  6. #6
    why not printing the query before executing? you'll know what value that $count holds.
    everyday is deadline

  7. #7
    Join Date
    Oct 2004
    Location
    Harrogate, Yorkshire, UK
    Posts
    21
    Yes i tried this and the output is what it should be. But after running the script, then checking the database, the result in the database is +7 of what is output on the page. This is how i identified it as a mysql problem.

    I've investigated this further though and it just get's more confusing. Now i'm thinking it isnt strictly a mysql issue, but i really can't explain it.

    Here's what i did. I coded my site to use the search engine friendly style url's; http://www.domain.com/index/1/page_name.htm; and everything worked fine apart from this problem.

    Now, i reverted back to normal url queries; http://www.domain.com/index.php?page=1; and guess what! No problems. The data is stored as it should be.

    But i can't understand how this affects the hitcounter part of my script. The only difference is a script that parses the url as opposed to using $_GET['page']. But it has nothing to do with the hit count part.

    It's really bizarre.
    Feel free to visit my sites: GTA San Andreas | My Portfolio

Posting Permissions

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