I have n number of textbox to get the name of the products and their quantity. So i used PHP array to get the value and its working fine. I tried the logic like if the user give duplicate products, then duplicate products is removed but their quantity is added with the same products.
<form method="post" action ="insert.php">
<input type =text name ="products[]" value = "">
<input type =text name ="quantity[]" value = "">
<!-- ...........
n numbers of textbox to add the products and quantity
--------- -->
<input type ="submit" value="submit"> </form>
insert.php:
$products = $_POST['products'];
$quantity = $_POST['quantity'];
for($i=0;$i<count($products);$i++)
{
$query = "INSERT INTO table_name (`products`,`quantity`) VALUES ('$products[$i]','$quantity[$i]')";
mysql_query($query);
}
the array come like
$products[0] = "Apple" $quantity[0] = "20"
$products[1] = "Orange" $quantity[1] = "10"
$products[2] = "Apple" $quantity[2] = "30"
Here products name apple is duplicate it occurs two times. So i remove the duplicate name apple and their quantity value should be added like 50(20+30)