Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:09:05+00:00 2026-06-08T03:09:05+00:00

Im trying to retrieve the values from MySQL database and convert it into int

  • 0

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!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:09:07+00:00Added an answer on June 8, 2026 at 3:09 am

    You should save yourself the headache and do it in one query:

    $result = mysql_query("UPDATE users SET karma_points = karma_points + $karma_points WHERE username = '$username'") or die(mysql_error());
    

    This will automatically increment your column karma_points for user $username with the value of $karma_points. Instead of doing the math in PHP and sending it back to MySQL, just do it in MySQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to retrieve values from database. I have a row which
I'm trying to retrieve odd values in a List of strings and convert them
I am trying to store a list of countries in a mySQL database. I
i am trying to retrieve date from Mysql db to my html form in
I am trying to retrieve the values from the following url: http://rentopoly.com/ajax.php?query=Bo . I
I have a list of values I am trying to enter into a mysql
I'm trying to call book details from the relationships table in my database, mysql
I'm trying to retrieve all the data id from a database where their tags(array)
When i am tring to retrive user information from mysql database, i am getting
I have a serious problem. Firstly, I am trying to retrieve values from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.