473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to UPDATE an integer field by adding a specific number?

117 100+
Ok, i got my point system working had to creat a new php for it the old page was killing the code session end lol.
But i am stuck, it don't seem to add the value it just replaces the old one..
so the old value, 5 after update 5 points new value 5 not 10.

So how do i make it so it adds the new value or reads the old one then adds plus 5?
old...5+ new...5= 10, or if the user has a value of 200, and it adds 5 it will be 205!

[PHP]<?php
$sql = "UPDATE users points = '$points' where userid = $uid";
$result = mysql_query($sql ,$db);

$sql = "delete from ingredients where userid = $uid";
$result = mysql_query($sql ,$db);

printf("<p><font face=arial size=-1><br /><br />Account Updated!<br /> 5 Points Recived...</font></p>");
?>[/PHP]
Aug 27 '07 #1
3 1966
gregerly
192 Expert 100+
Ok, i got my point system working had to creat a new php for it the old page was killing the code session end lol.
But i am stuck, it don't seem to add the value it just replaces the old one..
so the old value, 5 after update 5 points new value 5 not 10.

So how do i make it so it adds the new value or reads the old one then adds plus 5?
old...5+ new...5= 10, or if the user has a value of 200, and it adds 5 it will be 205!

[PHP]<?php
$sql = "UPDATE users points = '$points' where userid = $uid";
$result = mysql_query($sql ,$db);

$sql = "delete from ingredients where userid = $uid";
$result = mysql_query($sql ,$db);

printf("<p><font face=arial size=-1><br /><br />Account Updated!<br /> 5 Points Recived...</font></p>");
?>[/PHP]
If you want to add points to an existing database value you could do something like:

[PHP]<?
$sql="UPDATE users SET points = points + $points WHERE userid = $uid";
?>[/PHP]

The above query assumes that $points is already set and is an integer.

Hope that helps

Greg
Aug 27 '07 #2
Breana
117 100+
Yeah it works thanks, i tried the + idea but crashed the page when i did it but i do see where i went wrong lol thanx!
Aug 27 '07 #3
gregerly
192 Expert 100+
Yeah it works thanks, i tried the + idea but crashed the page when i did it but i do see where i went wrong lol thanx!
Not a problem. Glad I could help!

Greg
Aug 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Richard Cornford | last post by:
Anyone who has taken a look at the online FAQ today may have noticed that I have updated it. The majority of the changes are the updating of broken links and the implementation of that extensive...
5
by: Koen | last post by:
Hi all, I am experimenting with DAO. I wrote this sub to update one specific field of one specific row in one specific table. Nothing wrong with the SQL statement, but when I execute this I get...
6
by: Robert | last post by:
Hello, Accessors What I would like to do is create a multi-record table update. I have a table and a form for it. I want to modify it so that there is a new field (textbox) (not bound to a...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
9
by: Geraldine Hobley | last post by:
Hello I'm getting the above mentioned error in my applicatio I have a datagrid bound to a datasource like s MyDatagrid.DataSource = Mydataset.Tables(Order) - this all works fine However I...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
6
by: Dixie | last post by:
I have asked this question before, but I could not get the suggested solution work. So I will give more details this time. I have an append query that adds several hundred records to a table...
11
by: John | last post by:
Hi I had a working vs 2003 application with access backend. I added a couple fields in a table in access db and then to allow user to have access to these fields via app I did the following; ...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.