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

  • Home
  • SEARCH
  • 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 8149727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:54:35+00:00 2026-06-06T14:54:35+00:00

I have a datatable with user information and a column called ‘Bits’. There is

  • 0

I have a datatable with user information and a column called ‘Bits’. There is a transfer function and I would like to transfer x amount of bits from the logged in user to the user they specify. I have the following function that works, but I would like to know if there is a better (simpler, cleaner, quicker?) way to do all of this, and possibly return the row of the first SQL statement at the end. I am not an advanced MySQL user by any means, but I am pretty sure there is a function I am missing that could make this much easier.

function transferBits($toid, $amount)
{
    global $loggedInUser, $db;
    $fromid = $loggedInUser->user_id;
    $sql = "INSERT INTO `dl_Transfers` SET From_ID = '".$db->sql_escape($fromid)."',
        `To_ID`='".$db->sql_escape($toid)."',
        `Bits`='".$db->sql_escape($amount)."',
        `When`=Now()";
    $result = $db->sql_query($sql);
    $sql2 = "UPDATE `dl_Users` SET Bits = Bits - '".$db->sql_escape($amount)."' WHERE `User_ID` = '".$db->sql_escape($fromid)."'";
    $result2 = $db->sql_query($sql2);  
    $sql3 = "UPDATE `dl_Users` SET Bits = Bits + '".$db->sql_escape($amount)."' WHERE `User_ID` = '".$db->sql_escape($toid)."'";
    $result3 = $db->sql_query($sql3);
}
  • 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-06T14:54:36+00:00Added an answer on June 6, 2026 at 2:54 pm

    I think you could hit the update in single query by joining on the previous record id from your insert on dl_Transfers:

    UPDATE `dl_Transfers` r 
    JOIN `dl_Users` f ON ( r.From_ID = f.User_ID )
    JOIN `dl_Users` t ON ( r.To_ID = t.User_ID )
    SET f.Bits = f.Bits - r.Bits, t.Bits = t.Bits + r.Bits
    WHERE r.Transfer_ID = ?;
    

    Also as others stated in their comments, you should definitely use transactions here.

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

Sidebar

Related Questions

I have have icefaces datatable and when user clicks a row, I would like
First off I have an app that provides the user information about the amount
I have a WPF User control that binds to a DataTable and generates CheckBox
I have datatable with column name tag and 100 rows of data.I need to
I have a function in VB.NET that authenticates a user towards a MySQL database
I am using primefaces 3.2. I have prepared wizard which insert user information on
I have a datatable that - depending on the user selection - will generate
So I have a datatable that is being populated by user inputs. When I
I'm using JSF and I have a complex datatable where the user can sort
I have a DataTable that will be modified by the user. I want to

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.