Reputation: 5714
My page works as follows:
When he clicks submit the isset() function is triggered which will upload the selected team to the selected_team table in my db
Ok that is easy enough and it is working. Here is my problem, lets say the coach wants to change his selection for a certain fixture. He then goes to the selection page again and redo the whole process described above. But what now happens is that the same fixture_id for opponents is uploaded to the database (only with different playernames where he changed his selection)
Example: Where Selection has been changed for a fixture
Notice: How that the old data from 1st selection is still there and the new data from second selection just gets added to the table
What im looking for is, should the user re select a team for a certain fixture I want the new teams data to replace the old teams data. How do I go about doing this?
Please note this is a fictional database
Upvotes: 0
Views: 90
Reputation: 570
You will have to resend the fixture_id to change/edit page (by GET/POST) on clicking the edit fixture button (I assume) and then as Maximus mentioned, use ON DUPLICATE KEY UPDATE as the syntax described here : http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
or you can alternatively delete the key from the table manually.
Upvotes: 0
Reputation: 105547
Make fixture_id a unique or primary key field and use ON DUPLICATE KEY UPDATE syntax of MySQL
Upvotes: 3