1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

easy question - need some help

Discussion in 'PHP & Perl' started by cheva, Feb 9, 2010.

  1. cheva

    cheva Junior Member

    Joined:
    Aug 22, 2009
    Messages:
    117
    Likes Received:
    54
    Location:
    Aiur
    whats wrong with this code :S

    Code:
    mysql_connect($mysql_where, $mysql_username, $mysql_password);
    mysql_select_db($mysql_database);
    
    /*
     * test postback
     */
    include("includes.php");
    $new = $_REQUEST['new'];
    $uid = $_REQUEST['uid'];
    $total = $_REQUEST['total'];
    $oid = $_REQUEST['oid'];
    
    
    //$query_getuserid = mysql_query("SELECT id from members WHERE username= '".$uid."'") or die(mysql_error());
    //foreach(mysql_fetch_array($query_getuserid) as $userid);
    
    
    mysql_query("UPDATE members SET points=points+".$new." WHERE username='".$uid."'");
    mysql_close();
    echo "Success: ".$uid." earned ".$new." points\n";
    
    when i test postback for a given uid, the points get updated, but they keep adding after every couple of minutes.
    Its supposed to update the points once, and then close the statement.

    im no php guru so sum insight wud be appreciated
     
  2. showboytridin

    showboytridin Regular Member

    Joined:
    Sep 5, 2009
    Messages:
    348
    Likes Received:
    714
    Location:
    127.0.0.1
    Maybe I didn't understand your problem, but if you run that code several times, the points will always update each time you run it.
     
  3. aмillionaírе

    aмillionaírе Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 20, 2008
    Messages:
    532
    Likes Received:
    358
    First of all add
    PHP:
    if(! ) { echo mysql_error(); }
    for all of your mysql queries.

    Second, here
    PHP:
    mysql_query("UPDATE members SET points=points+".$new." WHERE username='".$uid."'");
    - try using the same apostrophe encapsulation as the userid variable.

    Third, is this file included/referenced by other executing scripts in your program?

    Fourth, is the global
    PHP:
    $_REQUEST
    really necessary? Is it not a POST/GET?

    I don't know the conditions of the script so I hope you can figure out. This error shouldnt be occurring as things look normal.

    On second notice, comparing to my own script, I don't think you should have '".$var."' as an encapsulation of a bare variable in a mysql query. Remove the double quotes and check again.
     
    Last edited: Feb 11, 2010