0

I have this mysqli query but it only inserts the first iteration. But when I comment the insert statement and just echo the values, the loop works fine.

$max = count($_SESSION['cart']);
for($x=0; $x<$max; $x++) 
{
    $product = $_SESSION['cart'][$x]['product_desc'];
    $quantity = $_SESSION['cart'][$x]['quantity'];
    $sql = "insert into waybills (product_desc, quantity) values ('$product', '$quantity')";
    mysqli_query($link, $sql);
}

Is there any error that is making the loop not working?

Maa
  • 31
  • 5
  • `echo $product; echo $quantity;` and what do you see? Any values? and put a `if(!mysqli_query($link, $sql)) { // Query Failed.";` instead. – DirtyBit Oct 03 '15 at 08:15
  • I have figure the issue. I was due to the index set for one of the fields – Maa Oct 03 '15 at 08:36

0 Answers0