I'm want to insert the id of every item in the cart to the database and couple this invoice line to an invoice that just has been created in the same case. at the moment if i press the button its adding a new invoice to the database and after this its adding every single product in the cart but now i need to replace the 1 in the second query with the invoice id that just has been created. How can i get this to work?
case "apply":
$curdate = date('Y-m-d');
// new invoice
$sql = "INSERT INTO invoice (user_user_id, dates) VALUES ('1', '$curdate')";
$result = mysqli_query($con, $sql);
// for each item in cart insert into invoiceline
foreach ($_SESSION["cart_item"] as $item){
$car = $item["id"];
$sql = "INSERT INTO invoice_line (car_car_id, invoice_invoice_number) VALUES ('$car', '1')";
$result = mysqli_query($con, $sql);
}
unset($_SESSION["cart_item"]);
break;
}
}
The invoice_id is not the primary but a foreign key, the table doenst have a primary key so i dont think i can use mysqli_insert_id?