I am working on a single product page. There are colors table in the database to define colors of each product. It looks like this;
| key | product_id | color |
+-----+------------+-------+
| 1 | 4 | black |
| 2 | 7 | red |
| 3 | 8 | blue |
| 4 | 8 | black |
+-----+------------+-------+
I insert the product via productController.php. No problem with this. Moreover, I want to insert colors to their own table with the same auto increment id. As you can imagine, there are multiple inputs for each color in the form. What is the right method and which functions should I use?
A simplified view of the form is below.
<form>
<div class="control-group">
<label class="control-label">Product Name</label>
<div class="controls">
<input type="text" name="productname" />
</div>
</div>
<div class="control-group">
<label class="control-label">Colors</label>
<div class="controls" id="color">
<input type="text" name="colors[]" />
<a href="javascript:void(0)" class="addcolor"> + Add</a>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Add Product</button>
</div>
</form>