sjk1000 Posted November 30, 2008 Share Posted November 30, 2008 Hi All I'm looking to update a table in a database based on the input to the form in the screenshot attached. It's a web portal with multiple stores potentially selling the same product. All the products are on the database. If a seller chooses to sell something, they enter the quantity and price details in the web front-end I've created. I figure the logic for what I'm trying to do would be IF SellerID AND Product ID exists then update the relevant field (ie they're just changing the details of a product they're already selling) ELSE INSERT a new row for that seller with the seller-specific details of the product. I've attached a screenshot of my seller_stock table. From my background reading It feels like I could use an INSERT ON DUPLICATE but that works with keys doesn't it? The alternative I think is to write the IF ELSE above. Is there a funciton that does what I'm looking for? Any help would be very much appreciated Thanks, Steve [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/134911-insert-field-if-exists-or-add-new-row-guidance-needed-please/ Share on other sites More sharing options...
gevans Posted November 30, 2008 Share Posted November 30, 2008 try looking up REPLACE instead of using INSERT and UPDATE Link to comment https://forums.phpfreaks.com/topic/134911-insert-field-if-exists-or-add-new-row-guidance-needed-please/#findComment-702586 Share on other sites More sharing options...
revraz Posted November 30, 2008 Share Posted November 30, 2008 Just base it on if any rows are returned. If so, update, if not insert. Link to comment https://forums.phpfreaks.com/topic/134911-insert-field-if-exists-or-add-new-row-guidance-needed-please/#findComment-702588 Share on other sites More sharing options...
sjk1000 Posted November 30, 2008 Author Share Posted November 30, 2008 Thanks for the quick response guys. I'll update the thread with the solution when I get to it. If I forget and someone's interested in the script feel free to drop me a reminder by Private Message. Cheers, Steve Link to comment https://forums.phpfreaks.com/topic/134911-insert-field-if-exists-or-add-new-row-guidance-needed-please/#findComment-702605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.