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. Link to comment https://forums.phpfreaks.com/topic/231996-check-for-duplicate-database-entries-and-add-to-them-or-create-new-ones/ 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. Link to comment https://forums.phpfreaks.com/topic/231996-check-for-duplicate-database-entries-and-add-to-them-or-create-new-ones/#findComment-1193483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.