genista Posted November 19, 2006 Share Posted November 19, 2006 Hi,Nice and simple one but still causing me issues!I want to change this query:[code=php:0]$query = "INSERT INTO supplierimages (image1, supplierid) VALUES ('$image1','$supplierid')";[/code]to UPDATE instead. The reason for this is I keep getting duplicate entry errors for the supplierid if it already exists in the database.I won't embaress myself by posting my attempts to update, please help!Thanks,G Link to comment https://forums.phpfreaks.com/topic/27785-noob-update-query-problem/ Share on other sites More sharing options...
printf Posted November 19, 2006 Share Posted November 19, 2006 Add a condition to the INSERT![code]$query = "INSERT INTO supplierimages (image1, supplierid) VALUES('" . $image1 . "', '" . $supplierid . "') ON DUPLICATE KEY UPDATE image1 = '" . $image1 . "';[/code]printf Link to comment https://forums.phpfreaks.com/topic/27785-noob-update-query-problem/#findComment-127124 Share on other sites More sharing options...
genista Posted November 19, 2006 Author Share Posted November 19, 2006 Great worked a treat!Thanks,G Link to comment https://forums.phpfreaks.com/topic/27785-noob-update-query-problem/#findComment-127174 Share on other sites More sharing options...
fenway Posted November 19, 2006 Share Posted November 19, 2006 This is of course contigent on an appopriate unique index. Link to comment https://forums.phpfreaks.com/topic/27785-noob-update-query-problem/#findComment-127189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.