Strange PHP problem

Discussion in 'PHP' started by krdzal, Aug 30, 2008.

  1. #1
    I want to increase by 1 a column in MySql table when the page is loaded, but the problem is that the value is increasing by 2
    Here is my code that i put it od the page

    mysql_query("UPDATE game SET hits=hits+1 WHERE id='".$game_id."'") or die (mysql_error());


    Any solution??????

    And now i have noticed, it is only doing in Firefox, it works fine in IE
     
    krdzal, Aug 30, 2008 IP
  2. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you paste the entire pages code? I suspect that it is somehow being run twice.
     
    Pos1tron, Aug 30, 2008 IP
  3. krdzal

    krdzal Peon

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    $game_id=$HTTP_GET_VARS['game'];
    mysql_query("UPDATE game SET hits=hits+0.5 WHERE id='".$game_id."'") or die (mysql_error());
    include('_drawrating.php');
    $sql = mysql_query('SELECT * FROM game where id='.$game_id.'');
    $row=mysql_fetch_array($sql);
    /*,hhits=hhits+1,whits=whits+1,thits=thits+1*/

    ?>
    <head>

    <script type="text/javascript" language="javascript" src="js/behavior.js"></script>
    <script type="text/javascript" language="javascript" src="js/rating.js"></script>
    </head>
    <link href="../css/rating.css" rel="stylesheet" type="text/css">
    <script type="text/JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
    //-->
    </script>
    <body>
    <table width="670" height="360" border="0" cellpadding="0" cellspacing="0" class="catpaddinggame playborder">
    <tr>
    <td width="238" height="25" align="left" valign="middle" bgcolor="#FFCC00" class="namegame">
    <?php echo($row['name']); ?> </td>
    .........................
    and continue It is very long to paste all
     
    krdzal, Aug 30, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hard to say what the problem is since you arent showing all your code for it...is this file being included by another?
     
    JAY6390, Aug 30, 2008 IP
  5. krdzal

    krdzal Peon

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes the file is included
     
    krdzal, Aug 30, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well then it seems like this file is included more than once, which is why you get the double entry for it. check that you dont reference it twice
     
    JAY6390, Aug 30, 2008 IP
  7. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #7
    You can easily debug with this little trick:
    Save your query as a variable and echo the value of the variable on the screen, in the debugging stage.

    For instance, split:
    mysql_query("UPDATE game SET hits=hits+1 WHERE id='".$game_id."'")
    into:
    $query = "UPDATE game SET hits=hits+1 WHERE id='".$game_id."'";
    $result = mysql_query ($query)

    Also, run a search, using your favorite text editor, to find all occurrences of mysql_query in your file and do the above for all mysql_query that you have in the script you wish to debug.
     
    ForumJoiner, Aug 30, 2008 IP
  8. dumsky

    dumsky Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    can you post the error you get?
     
    dumsky, Aug 31, 2008 IP
  9. LuisMiranda

    LuisMiranda Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You may be running that script twice, so you need to have a look at your code, looking if the script is included twice in a file or something like that.
     
    LuisMiranda, Aug 31, 2008 IP
  10. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #10
    well i also suffered from same problem in one of my site that was updating the field when i was aking for +1 and it was updating randomly sometime 2 5 or 10

    but that problem was solved auto i do not know how i guess there is the problem of data type conversion in the php plz try to make explicit data tye like for integers (integers) and for string (string) before passing to the my sql query

    soryy for my bad english
     
    octalsystems, Aug 31, 2008 IP