[Solved] How do i write a function to insert into database


Instead of putting $i in each of the names, give them array-style names like name="bill[]" and name="vendor[]". Then $_POST['bill'] and $_POST['vendor'] will be arrays, and you can loop through them:

$stmt = $conn->prepare("INSERT INTO yourTable (bill, vendor, detail, quantity, remark) VALUES (?, ?, ?, ?, ?)");;
$stmt->bind_param("sssis", $bill, $vendor, $detail, $quantity, $remark);
foreach ($_POST['bill'] as $i => $bill) {  
    $vendor = $_POST['vendor'][$i];
    $detail = $_POST['detail'][$i];
    $quantity = $_POST['quantity'][$i];
    $remark = $_POST['remark'][$i];
    $stmt->execute();
}

solved How do i write a function to insert into database