Put form data in Array

-1

Next, I have a database with some items and I display the items in this database using this template:

<?php $conexao = mysqli_connect("Host","User","Pass","banco");
        if( !$conexao ){
            echo "Erooooou.";
            exit;
        }

        $sql = "SELECT * FROM produtos ORDER BY id DESC";
        $consulta = mysqli_query($conexao, $sql);
        if( !$consulta ){
            echo "Erro ao realizar consulta. Tente outra vez.";
            exit;
        }


        while( $dados = mysqli_fetch_assoc($consulta) ){

            $imagem  = $dados['imagem'];

            echo "<div class='shop1'>";
            echo "<img src='$imagem'>";
            echo "<div><p>" .$dados['nome']. "</p></div>";
            echo "<div><p>" .$dados['valor']. "</p></div>";
            echo "<input type='number' name'quantidade'>";
            echo "</div>";      }?> 

This code is taking all the data from my bank and displaying, each one in a cute div, until then everything beauty, business is that I wanted to get the values typed in that input and send to a next page, so that I you can manipulate them, and save it again in another database, for example:

  

Get all data entered in the INPUT of all displayed items, along with the user ID that is in $ _SESSION and save them in another Logs database, so that when the User Logs page displays the quantity of each item he ordered.

Is this possible in PHP? How would you do that? And excuse me guys, I'm still learning, have patience with me!

    
asked by anonymous 03.04.2018 / 04:36

2 answers

0

You can put them in a $ _SESSION, example:

$_SESSION['nome'] = $dados['nome'];
$_SESSION['nome'] = $dados['valor'];

and retrieve them on the other page, then at the bottom of the page clear the session ...

unset($_SESSION[...]);

You can also put an input type = hidden and set the value with <?php echo $dados['nome']; ?> and make a $_POST on the next page to get the content.

I hope to have helped in some way, anything to be here.

    
03.04.2018 / 05:53
0

I got the answer, after analyzing the answer of $ ProgramadorCaio, I realized that I could be ugly using Array, and after studying a little I discovered that to send the input data was simply to put them with even NAME mas as if it were a vector, example:

echo "<input type='number' name='quantidade[]'>";

In this way, when the form is sent to the other page it is received as Array, after that I decided to save the data in a database, so it was easy to manipulate it with ease. Thanks to those who responded!

    
04.04.2018 / 16:37