Register multiple elements with several associated images in a DB at once only in php

0

I am making a function to register products on an E-Commerce platform.

The function is as follows: the user registers the base product after registering its variations (color and size, for example). If the base product has no variations, it will still be added to the table of variations for convenience.

To register the variation product, the user selects 1 or 2 variations, then sets the price and quantity of each variation, and then selects the images for each variation.

Ex: Registration of a shoe of the color red, sizes 38, 39 and 40. The user selects an X number of images referring to this sneaker, which has a primary variation of "red color", that is, these images will be displayed for all sizes of this sneaker, what matters in the selection of the images is the primary variation.

My problem starts here. How to connect the images to each corresponding product, and the number of images is variable? To add the other information (price and quantity) I have created an array of inputs, but I do not think with the images can be done so, due to this non limitation in the number that can be selected.

And all these products should be inserted at once into the BD, along with your images.

Part of the current code (products are dynamically created in php):

Div with product information inputs:

echo "                  <div class='small-9 columns'>";
echo "                    <input type='hidden' name='opVar1ProdutoPV[]' value='$opcao1'>";
echo "                    <input type='hidden' name='opVar2ProdutoPV[]' value='0'>";
echo "                    <div class='row'>";
echo "                      <div style='padding-top:1%' class='small-4 columns'>";
echo "                        <input name='precoReal[]' type='text' id='preco' placeholder='Preco:'>";
echo "                      </div>";
echo "                      <div style='padding-top:1%' class='small-4 columns'>";
echo "                        <input name='quantidade[]' type='text' id='qtd' placeholder='Quantidade'>";
echo "                      </div>";
echo "                      <div style='padding-top:1%' class='small-4 columns'>";
echo "                        <a id='remover$opcao1' class='button tiny small remover'>Excluir</a>";
echo "                      </div>";
echo "                    </div>";
echo "                  </div>";

Div record of images:

echo "              <div style='float:left' class='small-12 columns'>";
echo "                <ul id='adicionarImagensPV$opcao1'>";
echo "                   <li style='width:20%;display:inline-block'>";
echo "                      <input id='imagemPV$opcao1' type='file' name='imagensPV[]' class='imagensPV'>";
echo "                      <input id='imagemPV$opcao1' type='hidden' name='imagensPV[]' class='imagensPV'>";
echo "                   </li>";
echo "                </ul>";
echo "              </div>";

Simplified table breaks:

Product

CREATE TABLE IF NOT EXISTS produtovariacao ( idProdutoVariacao int (11) NOT NULL,    idProdutoBase int (11) NOT NULL,    idOpcaoVariacao1 int (11) DEFAULT NULL,    idOpcaoVariacao2 int (11) DEFAULT NULL,    quantidade int (11) DEFAULT NULL,    precoReal varchar (45) NOT NULL, )

CREATE TABLE IF NOT EXISTS produtoimagem ( idProdutoImagem int (11) NOT NULL,    idProdutoVariacao int (11) DEFAULT NULL,    linkProdutoImagem varchar (150) NOT NULL, )

The FK were all declared.

    
asked by anonymous 28.01.2016 / 16:13

0 answers