Im trying to retrieve the values from MySQL database and convert it into int and than adding 3 to it and than trying to store the update int into database.Im not getting any error or anything.Initial value that i retrieve from database is 5 and than im trying to add 3 and than update the database.Now the updated value should be 8 but its not instead it just 3.I have no clue about what am i doing wrong so please help me out.
My php code from the index.php is following:
else if ($tag == 'addQuestion'){ $username = mysql_real_escape_string($_POST['username']); $question = mysql_real_escape_string($_POST['question']); $tag1 = mysql_real_escape_string($_POST['tag1']); $tag2 = mysql_real_escape_string($_POST['tag2']); $tag3 = mysql_real_escape_string($_POST['tag3']); $time = $_POST['time']; $addQu = $db->addQuestion($username, $question, $tag1, $tag2, $tag3,$time); if($addQu){ $q_id = $addQu["id"]; $addQTA = $db->addQTA($username,$q_id,$question,$tag1,$tag2,$tag3); if($addQTA){ $getKP= $db->getKP($username); if($getKP){ //Having trouble at this part $kp = (int)$getKP['karma_points']; $ask_question_points = $kp + 3; $updateKP= $db->updateKP($username,$ask_question_points); if($updateKP){ $response["error"] =1; $response["msg"] = "updateKP in AddQuestion Succesfull"; echo json_encode($response); } else{ $response["error"] =1; $response["error_msg"] = "Error updateKP in AddQuestion"; echo json_encode($response); } } else{ $response["error"] =1; $response["error_msg"] = "Error inserting getKP in AddQuestion"; echo json_encode($response); } } else{ $response["error"] =1; $response["error_msg"] = "Error inserting QTA"; echo json_encode($response); } }else{ $response["error"] =1; $response["error_msg"] = "Error inserting question"; echo json_encode($response); } } Here is the code of the function from DB_functions.php which handles update query:
public function updateKP($username,$karma_points){ $result = mysql_query("UPDATE users SET karma_points = '$karma_points' WHERE username = '$username'") or die(mysql_error()); return($result); } Thank You!!