If i enter only 1 record. It saves only 1 record in the database which is fine. But if i put two records of the same fields. It saves multiple records in the database which shou
You can loop over only one field and use index for others to get appropriate data:
foreach ($_POST["Description"] as $index => $val )
{
$Description = $_POST['Description'][$index];
$Unit = $_POST['Unit'][$index];
$Quantity = $_POST['Quantity'][$index];
$Cost = $_POST['Cost'][$index];
$array = array($Description, $Unit, $Quantity, $Cost);
$query = "
INSERT INTO MRF_Request (Qty, Unit, Description, Cost)
VALUES ('$Quantity', '$Unit', '$Description', '$Cost')
";
odbc_exec($conn, $query);
}
You should also think about sanitizing your $_POST
data, to make the system secure and reliable.