If you always have one record too many, that probably means your quantity value is not correct (?).
Also, this is not related to your problem, you should use while($i<=$quantity)
instead of while($i<="$quantity")
. You do not need the "
s
This first block is ok:
$i=1;
while ($i<="$quantity")
{
$sql="INSERT INTO arivage (ID_Ship, Date_ariv, Date_achat, prov_id, Sph, cyl, Prod_type, Pord_color)
VALUES ('', '$date', '$date1', '$prov_id', '$sph', '$cyl', '$Prod_type', '$Prod_color')";
mysql_query($sql);
$i++;
}
The next if statement executes your query AGAIN, meaning you insert one too many rows. Removing the entire if statement would solve your "one too many rows is inserted" problem.
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
Alternatively, change your while loop to:.
$i=1;
while ($i<="$quantity")
{
$sql="INSERT INTO arivage (ID_Ship, Date_ariv, Date_achat, prov_id, Sph, cyl, Prod_type, Pord_color)
VALUES ('', '$date', '$date1', '$prov_id', '$sph', '$cyl', '$Prod_type', '$Prod_color')";
if(!mysql_query($sql, $con)) {
die('Error: ' . mysql_error());
}
$i++;
}