spinner0205 Posted March 28, 2011 Share Posted March 28, 2011 I have a PHP script that inserts data to a MySQL database. It may sometimes add entries that correspond with duplicate ones by a certain field. So if the 'username' field is already in the database I want it to add the information to that username entry. For example, bob's data is inserted and there is already a bob username field entry so the field 'balance' under this entry has a balance of 4000 and I want to add 200 to the balance. How would I go about doing this? Also if the username does not exist yet, then obviously have it create a new one. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 28, 2011 Share Posted March 28, 2011 If the field in question is indexed as UNIQUE, INSERT . . . ON DUPLICATE KEY UPDATE query would be a good place to start. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.