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 should only be two. What did i do wrong?
<td>1.<input name='Description[]' type='text' required></td>
<td><input type='text' name='Unit[]' placeholder='eg. reams,pcs,box' required></td>
<td><input type='number' name='Quantity[]' min='1' required></td>
<td><input type='number' name='Cost[]' min='1' required></td>
</tr>
I have a script that can add those fields again.
Here is the code:
foreach ($_POST["Description"] as $Description )
{
foreach ($_POST["Unit"] as $Unit)
{
foreach ($_POST["Quantity"] as $Quantity)
{
foreach ($_POST["Cost"] as $Cost)
{
$array = array($Description,$Unit,$Quantity,$Cost);
odbc_exec($conn, "INSERT INTO MRF_Request (Qty,Unit,Description,Cost) VALUES
('$Quantity' , '$Unit' , '$Description' , '$Cost')");
}
}
}
}