Hey guys. I have a program that when i button is clicked it should increase an attribute by one and decrease a stat point by one. For some reason it dosent decrease the stat point by one, it sets it to -1 but it does increase the attribute by one. I dont know what im doing wrong.. Below is the code for the function along with the functions that it calls. Any suggestions??

function addOneAtt($uname, $attname)
    {
        //Get current number of attribute point and stat points
        $dbarray = $this->getUserInfo($session->username);
        $attpts     = $dbarray['$attname'];
        $statpts = $dbarray['stat_pts'];
        
        //Add one to the current number of attribute points
        $attpts = $attpts + 1;
        
        //Subtract one from the current number of stat points
        $statpts = $statpts - 1;
        
        //Update attribute and stat points in database
        //function updateUserField($username, $field, $value)
        $this->updateUserField($uname, $attname, $attpts);
        $this->updateUserField($uname, stat_pts, $statpts);
    
        return;
    }
function getUserInfo($username)
    {
        $q = "SELECT * FROM ".TBL_USERS." WHERE username = '$username'";
        $result = mysql_query($q, $this->connection);
        //Error occurred, return given name by default
        if(!$result || (mysql_numrows($result) < 1))
        {
            return NULL;
        }
        /* Return result array */
        $dbarray = mysql_fetch_array($result);
        return $dbarray;

    }
function updateUserField($username, $field, $value)
    {
        $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'";
        return mysql_query($q, $this->connection);
    }

It looks like the value of the 'stat_pts' field in the database is zero, or possibly you have the field name wrong. Change it to this and you will be able to figure it out i think:

function addOneAtt($uname, $attname)
    {
        //Get current number of attribute point and stat points
        $dbarray = $this->getUserInfo($session->username);
        $attpts     = $dbarray['$attname'];
        $statpts = $dbarray['stat_pts'];
        echo '<br /><pre>';
        print_r($dbarray);
        echo '</pre><br />';
        
        //Add one to the current number of attribute points
        $attpts = $attpts + 1;
        
        //Subtract one from the current number of stat points
        $statpts = $statpts - 1;
        
        //Update attribute and stat points in database
        //function updateUserField($username, $field, $value)
        $this->updateUserField($uname, $attname, $attpts);
        $this->updateUserField($uname, stat_pts, $statpts);
    
        return;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.