0
 if($_POST['Product']){ do{ $Username = $_SESSION['username']; $ProductName = $_POST['Product']; $userid = $_SESSION['userid']; $address = $_SESSION['address']; $Price = $_POST['price']; $quantity = $_POST['quantity']; $sql = "INSERT INTO orders(productname,price,username,userid,address) VALUES('$ProductName','$Price','$Username','$userid','$address')"; if($quantity == 0){ echo "<script>alert('$quantity Item Added to your cart')</script>"; } $quantity - 1; if($quantity != 0){ mysqli_query($dbc,$sql); } else{ echo mysqli_error($dbc); } } while($quantity != 0); } 

This will code insert records to the database as long as the quantity is not equal to 0. I know that this error occur when the loop is endless but I'm not sure in what loop is endless.

1
  • while($quantity != 0); ---- "In a do--while loop, the test condition evaluation is at the end of the loop. This means that the code inside of the loop will iterate once through before the condition is ever evaluated." in short if this line return true,in short your loop is always going to run if you quantity is not equal to zero that's what you saying here, and use $quantity-- Commented Mar 27, 2017 at 1:00

1 Answer 1

1

The way you trying to decrease $quantity is wrong. Try changing $quantity - 1; to $quantity--;. When your'e not decreasing $quantity properly, you're caught in an infinite loop.

Sign up to request clarification or add additional context in comments.

2 Comments

while($quantity != 0); what about this line, does this line make any sense to you,
no that's line is fine, just tell him, why his loop is running endless, and your line is fine as well, sorry i was not clear enough, in short his code will work your solution and with his line as well, if he reduce the his quantity properly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.