Skip to content
Advertisement

How to change the quantity of the product if removed in PHP?

I have a form where I am inserting personal data and images. The user can add more than one image. Now when the user submits the form then I am inserting the data and images in the temporary table and creating a session for images that are as below.

JavaScript

I am getting the output which is correct (For example user added 3 images).

JavaScript

Till now, The User data in a temporary table. I don’t have any issues here.

Now What I am doing is, I am displaying all the images on the checkout page where the user can view the images for confirmation. So I use the below code.

JavaScript

I am using the below script for remove and restore.

Note: The Below script is used only for adding the class and display the remove and restore the text. It is not completely removing from the session.

I don’t want to remove from the session because the user can reactive the image again.

JavaScript

Check the below image. I am getting this output.

Note: The second image removed but still I want to show it to the user.

enter image description here

Now If I click on Proceed to pay button then I am inserting the all the data in the real table(I am sharing only checkout query here)

JavaScript

Now my main issue is, I am getting 3 qty instead of 2. I removed second image but still giving me 3 qty.

Would you help me out with this issue?

Advertisement

Answer

You are getting the quantity by counting the amount of images is the session variable

JavaScript

The session variable is a server-side variable, you cannot change this with javascript. I would suggest using jQuery to remove or add 1 to the quantity when remove or restore is clicked.

example:

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