user5207499
user5207499

Reputation: 137

Fatal error: Maximum execution time

   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.

Upvotes: 0

Views: 40

Answers (1)

Adir Ratzon
Adir Ratzon

Reputation: 181

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.

Upvotes: 1

Related Questions