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.
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--