singingsands Posted February 27 Share Posted February 27 I want to insert (not replace) data into a record that already exists. The user would not know the ID of the record so I have to use a concatenation of 2 fields to get the correct record. This is the sort of thing I want but I know it isn't right. INSERT INTO table ('field5') values('value1') WHERE ('field1') == 'value2' && ('field2')=='value3'; What's the right way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/326884-insert-into-record-where-2-fields-must-match/ Share on other sites More sharing options...
Barand Posted February 27 Share Posted February 27 Inser queries cannot have a WHERE clause. You need an UPDATE query Quote Link to comment https://forums.phpfreaks.com/topic/326884-insert-into-record-where-2-fields-must-match/#findComment-1650575 Share on other sites More sharing options...
Solution Phi11W Posted February 28 Solution Share Posted February 28 18 hours ago, singingsands said: I want to insert (not replace) data into a record that already exists. You INSERT new records. You UPDATE existing records. When you do this, you replace the values that were in that record before you updated it. There is no way around this - it's just how databases work. What you're attempting to do is an UPDATE: UPDATE `table` SET field5 = 'value1' WHERE field1 = 'value2' AND field2 = 'value3' Regards, Phill W. 1 Quote Link to comment https://forums.phpfreaks.com/topic/326884-insert-into-record-where-2-fields-must-match/#findComment-1650614 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.