Jump to content


Photo

**SOLVED** Add to a number


  • Please log in to reply
2 replies to this topic

#1 Imperialdata

Imperialdata
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 31 March 2006 - 07:47 PM

I have a database which I would like to do the following:

In table_userinfo I have columns user_id and user_credits.
I wish to add 50 to the number stored in user_credits for a single user (say user_id=5) via a php script

How is this best achieved? I have succeeded in retrieving the data from the field using

return mysql_fetch_array($res,MYSQL_ASSOC);

but I am struggling to add 50 to it and drop it back into the table.



Thanks in advance



----------------------------------------------------------

[a href=\"http://www.TheBikeForum.com\" target=\"_blank\"]Like Motorcycles?[/a]

----------------------------------------------------------

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 31 March 2006 - 08:05 PM

Simply

$creds = 50;
$user = 5;

$sql = "UPDATE user_info SET user_credits = user_credits+'$creds' WHERE user_id = '$user' ";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Imperialdata

Imperialdata
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 01 April 2006 - 10:08 AM

Thanks, that helps a lot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users