I am creating an admin panel, which can insert products into database. The items are t-shirts, which have sizes, colors and quantity. The same item can have several sizes, colors and for each row it should have its own quantity. Eg. Product with id 100 can have sizeid 1 colorid 1 and quantity 2. Now the same product will be stored with same id 100, but different size, lets say sizeid 2, with same color, colorid 1 and different quantity. I am using checkboxes for the sizes and colors and fetch them with foreach.
add_panel.php
<input type="checkbox" name="color[]" value="<?php echo $colorname;?>">
</td>
<td><input type="text" name="quantity[]"></td>
add_success.php
$color = $_POST['color'];
$quantity = $_POST['quantity'];
<?php
foreach ($color as $_colorvalue){
$color = mysql_query("SELECT * FROM color
WHERE colorname = '$_colorvalue'");
$fetch = mysql_fetch_array($color);
extract($fetch);
foreach ($quantity as $_qtyvalue){
echo $_qtyvalue;
$insert_desc = mysql_query("INSERT INTO productdesc
(pid, productid_foreign, sizeid, quantity, colorid)
VALUES ('', '$productid', '$sizeid', '$_qtyvalue', '$colorid')");
}}
When I make the same with the quantity inside those brackets, the item is stored multiple times, it executes both foreach. Now I need a solution to make a form that will store the same product, but with several sizes, colors and quantity in the table. Please help and ask, if I am not clear enough.