ChidoriSoul Posted October 1, 2009 Share Posted October 1, 2009 Hello. I am currently trying to run a site where you can randomly find some "credits" on the ground.I am currently trying to make a system where a user finds them, then it adds a set amount (5) to a field in my database. So if a user has 100 credits, then goes on the page, he/she would now have 105. Anyone to help me with this? Link to comment Share on other sites More sharing options...
chibineku Posted October 1, 2009 Share Posted October 1, 2009 "UPDATE credit SET amount = amount+5 WHERE userid = $_SESSION["userid"]";Change field names to match the ones in the table, and however you identify the user. If you are saving this in a table with the field for credit already in existence even if empty, that's fine. If you are saving the credit in a new table, then you will need to check if they have a record already. If not, you need to create one, if so, you need to update. I just discovered a new condition - ON DUPLICATE KEY UPDATE, which allows you to do both at once - if there is already a row with the unique index set, the table is updated, otherwise a new row is made.Definately worth checking out for this unless the field is already in another table which, by design, has a record for the user. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.