Jump to content

insert field if exists or add new row - guidance needed please


sjk1000

Recommended Posts

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.