barefootsanders Posted April 8, 2007 Share Posted April 8, 2007 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); } Link to comment https://forums.phpfreaks.com/topic/46183-query-not-setting-value-to-the-proper-number/ Share on other sites More sharing options...
esukf Posted April 8, 2007 Share Posted April 8, 2007 <?php $attpts = $dbarray['$attname']; //should this be $dbarray['attpts']?? $this->updateUserField($uname, $attname, $attpts); //$attname should be 'att_pts'?? $this->updateUserField($uname, stat_pts, $statpts); // need quotes around stat_pts i.e 'stat_pts' Alternatively, you can achieve the whole thing by just using an update statement like $sql = "UPDATE TBL_USERS SET stat_pts = stat_pts + 1, att_ps = att_ps - 1 WHERE username = '$username'"; Link to comment https://forums.phpfreaks.com/topic/46183-query-not-setting-value-to-the-proper-number/#findComment-224574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.