Jump to content

Subracting a number from decimal value in mysql


PNewCode
Go to solution Solved by requinix,

Recommended Posts

Hello wise and wonderful people!

Today I am tackling a task to make a function to subtract a value by decimal from mysql database.
I am including the part that is the functioning part of the script to show.
Right now, it works perfect for whole numbers (1, 3, 9, etc). In this bit, you can see it's at 1

The problem is, when I change this to .5 then it doesn't subtract anything at all.
Could this be because in my database I have the column set to int(225) - null?

PS: I only included this part because everything else is just connections and images and stuff like that. So far, what you see below works perfect for whole numbers.

Edit: The goal is to subtract 1/2 token (number) so if the user has 3 tokens, then this will bring it to 2.5 tokens
 

 if(isset($_POST['submit3'])){
$user_updated_token = ($user_token) - 1;
     
 }else{
    
$user_updated_token = ($user_token) - 1;
}

  $sql_l = "UPDATE users SET token='$user_updated_token' WHERE id=$user_id";

 

Edited by PNewCode
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.