UPDATE MySQL Error

Discussion in 'PHP' started by PwrUps, Jul 17, 2007.

  1. #1
    So here's what's happening. I'm trying to update the value of video_views by one and putting it into the table.

    $video['views']++;
    $query = "UPDATE videos SET video_views='{$video['views']}' WHERE video_id='{$video['id']}'";
    $result = @mysql_query($query);

    Everytime it goes through this statement, it increments the views by two instead of one. Anyone know why this might be happening?

    $video is an array that holds various information on the video and is filled in earlier in the code.
     
    PwrUps, Jul 17, 2007 IP
  2. Janissary

    Janissary Well-Known Member

    Messages:
    375
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    140
    #2
    Where do you get $video['views'] ?
     
    Janissary, Jul 17, 2007 IP
  3. PwrUps

    PwrUps Peon

    Messages:
    377
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's the value of views before the update.
     
    PwrUps, Jul 17, 2007 IP
  4. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $query = "UPDATE videos SET video_views = video_views + 1 WHERE video_id='{$video['id']}'";
    $result = @mysql_query($query);
    Code (markup):
     
    rgchris, Jul 17, 2007 IP