Skip to content
Advertisement

How do I substract values from product table and order table?

orders table

enter image description here

products table

enter image description here

The pictures are order and product table. I am trying to change my stock quantity of products where admin confirm the order of the customer and the product quantity will change according to the quantity added from the order table.

What I have tried:

I tried the code as below but there are no changes. Nothing works.

JavaScript

}

Advertisement

Answer

I’ve tried your code in my local server creating a database, but setting some variables

JavaScript

and the code is working just fine, so I’ve tried some other values to reproduce your error, so changing the uid:

JavaScript

The order is updated but the product doesn’t.

This is because in the line

JavaScript

You are filtering the order by user_id, but the order may not have been created from the registered user.

You can verify this adding the following dump in your function:

JavaScript

You expect to receive

JavaScript

but you will receive:

JavaScript

Therefore, you must remove the user_id filter to allow the registered user to update the quantity in the product table

But if the user_id isn’t the order’s creator and correspond to the last modifier user, you must update the user_id value in the same statement line when you update the status and confirmation date

Hope this clears your doubts and solves your problem

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement