473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to achieve AddToCart Without quantity?

aveeva
33
I am following the below module,

https://www.webslesson.info/2018/04/...-ajax-php.html

How can i use without quantity [Product Name, Price, total, Action] i tried lot fail again and again. I am learning stage in PHP, any help pls welcome.
Jun 18 '19 #1

✓ answered by Luuk

I did not test what happens when you use AddtoCar without quantity, but looking at the code is seems pretty obvious why you cannot add an object with quantity=0

Do examine this piece of code from 'index.php'
Expand|Select|Wrap|Line Numbers
  1.         if(product_quantity > 0)
  2.         {
  3.             $.ajax({
  4.                 url:"action.php",
  5.                 method:"POST",
  6.                 data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
  7.                 success:function(data)
  8.                 {
  9.                     load_cart_data();
  10.                     alert("Item has been Added into Cart");
  11.                 }
  12.             });
  13.         }
  14.         else
  15.         {
  16.             alert("lease Enter Number of Quantity");
  17.         }

6 1695
Luuk
1,047 Expert 1GB
I did not test what happens when you use AddtoCar without quantity, but looking at the code is seems pretty obvious why you cannot add an object with quantity=0

Do examine this piece of code from 'index.php'
Expand|Select|Wrap|Line Numbers
  1.         if(product_quantity > 0)
  2.         {
  3.             $.ajax({
  4.                 url:"action.php",
  5.                 method:"POST",
  6.                 data:{product_id:product_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
  7.                 success:function(data)
  8.                 {
  9.                     load_cart_data();
  10.                     alert("Item has been Added into Cart");
  11.                 }
  12.             });
  13.         }
  14.         else
  15.         {
  16.             alert("lease Enter Number of Quantity");
  17.         }
Jun 22 '19 #2
aveeva
33
I just want to conform myself, your code as same as above shown code? May I know what change in the code?
Jun 24 '19 #3
Luuk
1,047 Expert 1GB
Because you show an 'external link' to the code, I have copied the code to this site, so everyone can see what piece is handling the quantity stuff.. (If they are really interested in the complete code, they can follow the link (for as long as it exists...))

I did not change the code, because to /me your problem is SOO obvious (sorry), so I just copied relevant piece of code.
Jun 25 '19 #4
zmbd
5,501 Expert Mod 4TB
aveeva:

Luuk has given you a very good answer, what have you done to actually troubleshoot your code?

I've set Luuk's post#4 as best answer

In the future please keep in mind that we normally require that the relevant part of the code be inserted and formatted using the [CODE/] format tool to be part of your thread for several reasons:
1) Such links are can be transient (as Luuk pointed out).
2) As many of us answer questions at work while on breaks or between project down times - the companies we work for often block code sites
3) Links like this can lead to malicious websites. I actually used a service that checks sites such that you linked to for threats before allowing this thread to stay.
Jun 26 '19 #5
Try quantity = 1 would be a simple solution
Jul 5 '19 #6
gits
5,390 Expert Mod 4TB
no - its not. The question was why a quantity of 0 wont work and Luuk did show the code that is responsible for that. Code is always doing as it is written - if you write a condition that checks for a value > 0 then it will fail of course when the value is 0. Simple as that.

Why anyone would like to add any kind of item to a cart with a quantity of 0 is another question and somehow beyond my imagination-capabilities though.
Jul 5 '19 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michael J. Astrauskas | last post by:
I'm developing a fairly basic shopping cart. My original implementation had the user click on a link to add an item to the cart (addtocart.php?item=123456). I figured it could just increase the...
11
by: Mark Schneider | last post by:
I'm trying to avoid using <table> for formatting purposes where other, reasonable means exist. I'm stuck trying to find a way to find an equivalent for the code below. <table align="center">...
2
by: Gary Vidal | last post by:
I have a shopping cart webpage that shows a product and the Quantity they would like to order: When you click the link I want to take the quantity that they entered in the textbox and post that to...
4
by: John | last post by:
I get the feeling this is a pretty classic problem, but I'm a bit of an uber newber. Apologies! Products page, user enters a quantity and clicks one of my "Add to Cart" buttons, which bubbles up...
2
by: nielsh | last post by:
Hello, I have a Excel document with multiple colums. I want to use te data from 2 colums (filename & quantity). First i want to know the quantity, because when the quantity is '3' i want to make a...
2
by: Seraph Jiang | last post by:
I am writing a NotifyIcon app. I want to use Left mouse click to pop up a ContextMenuStrip. Currently, I use ContextMenuScrip.Show(x,y) to display it. But it always show a windows at taskbar...
3
by: hagarwal | last post by:
People, Here's my situation: 1. I have a web browser component that does not support Javascript (well it does, but we've disabled it) 2. I have to display some HTML in it, where the user has a...
5
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"?...
9
by: FunkHouse9 | last post by:
I am trying to set up a page that calculates a total ad price based on a word count value. I have the word count displaying properly in op3, but just can't get the price even close to working right....
4
by: hannoudw | last post by:
I am trying to get the below statement work in VBA, but I always get the following error message: "Else without if" Hope that someone help me ... If (Qty < SolderieQty Or Qty = SolderieQty) Then...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.