Query with arrays not working PHP SQL

0

To edit a report, I need to get everything and turn it into an Array.

I can not use UPDATE because the user can add more rows, having to add.

In this way, I thought of first to delete the data that codeReport = '$ codeReport' and then give INSERT with the obtained data.

// Para pegar $codigoRelatorio //
if(isset($_GET['codigo'])){

    $codigoRelatorio = $_GET['codigo'];

    }






//////////////////////// PRESSIONAR O BOTÃO //////////////////////////
            if(isset($_POST['insertar']))

            {


            $items1 = ($_POST['codigoRelatorio']);

            $items2 = ($_POST['clienteRelatorio']);
            $items3 = ($_POST['nf']);
            $items4 = ($_POST['qtd']);
            $items5 = ($_POST['valorunitario']);
            $items6 = ($_POST['valorsubtotal']);

            $items7 = ($_POST['clientePrincipal']);
            $items8 = ($_POST['dataRelatorio']);

            $items9 = ($_POST['dataEntrega']);

            ///////////// SEPARAR VALORES DE ARRAYS, NESTE CASO SÃO 6 ARRAYS UM POR CADA INPUT (CODIGO, CLIENTE, NF, QUANTIDADE, PORPALETE, TOTAL)  ////////////////////)
            while(true) {

                //// RECUPERAR VALORES E JUNTÁ-LOS ////////
                $item1 = current($items1); //Código Relatorio
                $item2 = current($items2); //Cliente Relatorio
                $item3 = current($items3); //NF
                $item4 = current($items4); //Quantidade de Paletes
                $item5 = current($items5); //Valor por Palete
                $item6 = current($items6); //Valor Total
                $item9 = current($items9); //Data de Entrega
                $item7 = current($items7); //Cliente Principal
                $item8 = current($items8); //Data Relatorio

                ////// CONCATENAR PARA RESPECTIVAS VARIÁVEIS ///////////////////
                $codigo=(( $item1 !== false) ? $item1 : ", &nbsp");
                $cliente=(( $item2 !== false) ? $item2 : ",  ");
                $nf=(( $item3 !== false) ? $item3 : ",  ");
                $qntd=(( $item4 !== false) ? $item4 : ",  ");

                $porPalete=(( $item5 !== false) ? $item5 : ",  ");
                $total=(( $item6 !== false) ? $item6 : ",  ");
                $principal=(( $item7 !== false) ? $item7 : ", &nbsp");

                $dataRelatorio = (( $item8 !== false) ? $item8 : ", &nbsp");
                $dataEntrega = (( $item9 !== false) ? $item9 : ", &nbsp");

                //// CONCATENAR VALORES PARA FUTURA INSERÇÃO ////////
                $valores='('.$codigo.',"'.$cliente.'","'.$nf.'","'.$qntd.'","'.$porPalete.'","'.$total.'","'.$principal.'","'.$dataRelatorio.'","'.$dataEntrega.'"),';

                ////////  COMA É TERMINADO COM CADA LINHA, SUBTRAI COM FUNCÇÃO SUBSTR NA ÚLTIMA FILA /////////////////////
                $valoresQ= substr($valores, 0, -1);



                // QUERY PARA DELETAR DADOS ANTIGOS //
                $sql = "DELETE FROM relatorio WHERE codigoRelatorio = '$codigoRelatorio'";
                $qr = mysqli_query($connection, $sql) or die(mysqli_error());


                // QUERY PARA INSERIR NOVOS DADOS //
                $sql1 = "INSERT INTO relatorio (codigoRelatorio, clienteRelatorio, nf, quantidadePaletes, valorPorPalete, total, clientePrincipal, dataRelatorio, dataEntrega) 
                VALUES $valoresQ";
                $sql1Res=$connection->query($sql1) or mysqli_error();


                $idUltimo = mysqli_insert_id($connection);






                // Up! Next Value
                $item1 = next( $items1 );
                $item2 = next( $items2 );
                $item3 = next( $items3 );
                $item4 = next( $items4 );

                $item5 = next( $items5 );
                $item6 = next( $items6 );
                $item9 = next( $items9 );
                $item8 = next( $items8 );
                $item7 = next( $items7 );

                // Check terminator
                if($item1 === false && $item2 === false && $item3 === false && $item4 === false && $item5 === false && $item6 === false && $item7 === false && $item8 === false && $item9 === false) break;

            }



                if($sql){
                    echo "
        <script>window.open('verRelatorio.php?id=$idUltimo')</script>
        <meta http-equiv='refresh' content='0; url=relatorios.php' />
        <script type='text/javascript'>alert ('Dados foram Inseridos com Sucesso!!')</script>
    ";
                } else {
                    echo "
        <meta http-equiv='refresh' content='0; url=relatorios.php' />
        <script type='text/javascript'>alert ('Dados não foram Atualizados com Sucesso!!')</script>
    ";
                }

            }

? >

At first it works fine, but it deletes the old data, but when you add the new data it only adds the first line that the user has filled in and not all .

Finally, I tried other ways too, but I could not. It seems to be all right, but does not add the data correctly.

Can anyone help ????

    
asked by anonymous 26.12.2016 / 16:15

0 answers