SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru Angry Coder's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple counter not working

    Hello,

    I have this PHP code:

    PHP Code:
    mysql_query("UPDATE game SET counter = (counter + 1) WHERE id = $ID LIMIT 1"); 
    It's incrementing my counter field by 2 not 1!!!

    Why?

    Please help.
    Why It Doesn't Work?!

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    most likely due to other code problems with your script, or your form being submitted more than once.

    your code there says to increment it by one so that is all that mysql will do for each time the UPDATE is called.

    Show us the PHP code the query gets called in.

    Oh and a moderator will probably move this to the PHP forum area.

  3. #3
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    and if the id column is your primary key, then the LIMIT 1 is not needed.


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
  •