MySQL Subtraction Problem From PHP (Unsigned Int)

I am trying to subtract the value in the field directly in MySQL. I can add correctly as I have seen the correct updates. However I want to be able to store the negative of the value and not just keep itself at 0.

My query from PHP is as follow:

mysql_query("UPDATE registry SET npurchased = npurchased + '".$qty."', nremain = nremain - '".$qty."' WHERE regid = '".$regid."'" );

The MySQL field nremain is set as an unsigned int.

Please let me know where my problem lies.
namsu55Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

namsu55Author Commented:
Maybe I am a bit crazy today. UNSIGNED. Let me get rid of that.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kumaranmcaCommented:
Hi

Try the following query... its helpful for you

UPDATE tblrecords SET `leagueID` = leagueID+2, `seriesID`= IF((seriesID-1)<0, 0, seriesID-1) WHERE recordID= 1

mysql_query("UPDATE registry SET npurchased = npurchased + '".$qty."', nremain =IF(( nremain- - '".$qty."')<0, 0,  nremain- - '".$qty."')  WHERE regid = '".$regid."'" );
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.