How to send form data via _SESSION?

0

How can I send data from the first form to the second one and then send it to mysql?

I've tried everything and when I send it to the database, the second data arrives. I'll put down my forms and mysql.

I'm grateful right away.

Form 1

    <main>

<div class="pedidos">
<form method="post" action="fazer2.php">
<table >
    <tr>
        <td colspan="4" width="100">
         <span>Mesa</span>
         <input type="text" id="numero_mesa" name="numero_mesa">
         <label>
                    <span>Comanda:</span>
                    <?php
                    $row = mysqli_fetch_array($resultado_id);
                     echo '<span>'.$row['ultimo'].'</span>';
                    ?>

                </label>
                <br>
                <br>
        </td>

    </tr>
    <tr>
    <td width="280" bgcolor="#00BFFF">Refeição</td>
    <td width="70" bgcolor="#00BFFF">Quantidade</td>

    </tr>

    <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Costela de Tambaqui sem Espinha">Costela de Tambaqui sem Espinha</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Lombo de Tambaqui Frito sem Espinha">Lombo de Tambaqui Frito sem Espinha</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Caldeirada de Tambaqui sem Espinha">Caldeirada de Tambaqui sem Espinha</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Caldeirada de Tucunaré">Caldeirada de Tucunaré</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Peixe no Tucupi com Camarão">Peixe no Tucupi com Camarão</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Escabeche de Pirarucu">Escabeche de Pirarucu</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Escabeche de Tambaqui">Escabeche de Tambaqui</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
     <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Escabeche de Tucunaré">Escabeche de Tucunaré</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Tucunaré Frito">Tucunaré Frito</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Sardinha Frita">Sardinha Frita</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Jaraqui Frito">Jaraqui Frito</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Pacu Frito">Pacu Frito</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Filé de Pirarucu Frito">Filé de Pirarucu Frito</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Filé de Pirarucu a Milanesa">Filé de Pirarucu a Milanesa</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
        <tr>
        <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Guisado de Pirarucu">Guisado de Pirarucu</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
       <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Caldeirada No Tucupi com Camarao">Caldeirada No Tucupi com Camarão</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
       <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Caldinho de Tambaqui">Caldinho de Tambaqui</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
      <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Feijão">Feijão</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
     <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Arroz">Arroz</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
     <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Farofa">Farofa</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
     <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Vinagre">Vinagre</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
    <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Isca de Pirarucu">Isca de Pirarucu</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

    </tr>
    <tr>
    <td width="280"><input type="checkbox" name="pedido_refeicao[]" value="Bolinho">Bolinho</td>
        <td width="20"><input type="text" name="num_refeicao[]" size="7"></td>

</table>
 <br>
<input class="btn" type="submit" value="Proximo" name="Proximo"> 
</form>

Form 2

<?php
session_start();

error_reporting(-1);
ini_set('display_errors', 'On');

//Criar a conexao
$link = new mysqli ("localhost", "root", "", "peixaria");
if($link->connect_errno){
     echo"Nossas falhas local experiência ..";
     exit();
}

$sql= "SELECT MAX(m.id_pedido)+1 as ultimo FROM mpedido as m WHERE id_pedido ORDER BY m.id_pedido DESC LIMIT 1";

$resultado_id= mysqli_query($link,$sql);


$mesa = isset($_POST['numero_mesa']) ? $_POST[''] : '';
$_SESSION['numero_mesa'] = $mesa;

$pedido = isset($_POST['pedido_refeicao']) ? $_POST['pedido_refeicao'] : '';
$_SESSION['email'] = $pedido;

$bebida = isset($_POST['num_refeicao']) ? $_POST['num_refeicao'] : '';
$_SESSION['num_refeicao'] = $bebida;

?>

    <main>

<div class="pedidos">
<form method="post" action="relatorio.php">
<table >
    <tr>
   <tr>
        <td colspan="4" width="100">
         <span>Mesa</span>
         <input type="text" id="numero_mesa" name="numero_mesa">
         <label>
                    <span>Comanda:</span>
                    <?php
                    $row = mysqli_fetch_array($resultado_id);
                     echo '<span>'.$row['ultimo'].'</span>';
                    ?>

                </label>
                <br>
                <br>
        </td>

    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Fanta Laranja 1l">Fanta Laranja 1l</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Fanta Laranja 2l">Fanta Laranja 2l</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola 1l">Cola Cola 1l</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola 2l">Cola Cola 2l</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Bare 2l">Bare 2l</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Fanta Uva">Fanta Uva</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Fanta Laranja">Fanta Laranja</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Sprit">Sprit</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola">Cola Cola</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Cola Cola zero">Cola Cola zero</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Guaraná Antarctica">Guaraná Antarctica</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Guaraná Baré">Guaraná Baré</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Manga">Suco Manga</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Pessego">Suco Pessego</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
        <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Goiaba">Suco Goiaba</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Uva">Suco Uva</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Maracujá">Suco Maracujá</td>
        <td width="00"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Laranja">Suco Laranja</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Suco Caju">Suco Caju</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Agua Mineral">Agua Mineral</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Agua com Gas">Agua com Gas</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Cerveja em Lata">Cerveja em Lata</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>
        <td width="280"><input type="checkbox" name="pedido_bebida[]" value="Limonada Natural">Limonada Natural</td>
        <td width="20"><input type="text" name="num_bebida[]" size="7"></td>
    </tr>
    <tr>

</table>
 <br>
<button class="btn" type="submit">Fazer Pedido</button> 
</form>
</div>



    </main>

and mysql

<?php
error_reporting(-1);
ini_set('display_errors', 'On');

//Criar a conexao
$link = new mysqli ("localhost", "root", "", "peixaria");
if($link->connect_errno){
     echo"Nossas falhas local experiência ..";
     exit();
}

       if($_POST)
{  
    $numero_mesa = $_POST['numero_mesa'];
    $pedido_refeicao = implode(', ', $_POST['pedido_refeicao']);
    $num_refeicao = implode(', ', $_POST['num_refeicao']);
    $pedido_bebida = implode(', ', $_POST['pedido_bebida']);
    $num_bebida = implode(', ', $_POST['num_bebida']);
    $sql="INSERT INTO mpedido(numero_mesa,pedido_refeicao,num_refeicao,pedido_bebida,num_bebida) VALUES('$numero_mesa','$pedido_refeicao','$num_refeicao','$pedido_bebida','$num_bebida')";
        $resultado_pedido = mysqli_query($link,$sql);
}


         $sql= "SELECT id_pedido,numero_mesa,pedido_refeicao,num_refeicao,pedido_bebida,num_bebida,data FROM mpedido ORDER BY id_pedido DESC LIMIT 1";
        $consulta = mysqli_query($link,$sql);

?>
    
asked by anonymous 30.01.2017 / 20:38

2 answers

1

Dude, I think it's much safer to use $ _SESSION with openssl. I save everything in session and I elaborate the form according to what I have in the session so I can have several formulations on the same page without leaving it all using $ _POST as the sending mode and all this is analyzed with regex for each field and placed in $ _SESSION.
A schematic of how I do:

if(!empty($_SESSION[NOMEDASESSAO]['contato']['status']) OR $_SESSION[NOMEDASESSAO]['contato']['status'] != 1){

if($_SESSION[NOMEDASESSAO]['contato']['nome'] == null){
Formulario();
} elseif($_SESSION[NOMEDASESSAO]['contato']['email'] == null){
Formulario();
} elseif($_SESSION[NOMEDASESSAO]['contato']['assunto'] == null){
Formulario();
} elseif($_SESSION[NOMEDASESSAO]['contato']['texto'] == null){
Formulario();
} elseif($_SESSION[NOMEDASESSAO]['contato']['erros']['texto'] == 1){
Formulario();
}else{
$_SESSION[NOMEDASESSAO]['contato']['ok'] = 1;
Formulario();
}
}

The Form () is set up according to the data flow. Only if everything is right is that the system makes a new form with the captcha field. No problem if at this point the person tries to change something and clicks send because all the fields go through the regex with each press of the button. Simple, fast and easy.
I use this there in the contact page (I do not have contact email to avoid spam), and I follow the same principle for the login page, to remember password, register and everything I want to do purely in PHP without having to to use Javascript. Good boy studies!

    
23.02.2017 / 00:28
1

I recommend you use Ajax with JQuery, function $ .post (), is more "beautiful", if you do not want to use it, do the following, give the action of form1.php to form2.php. Inside your form2.php you will have $ _POST available. Do this:

var_dump($_POST);

Once this is done, get the $ _POST data, like this:

input type="text" name="name" value="$ _ POST ['value']"

Now in the inputs of your form2.php just call the values. $ _POST ['value']

Now giving the submit, go to mysql. I recommend using var_dump on your form2 so you can: D

-General issue, let me summarize

This is your 1st form

<div class="pedidos">
<form method="post" action="fazer2.php">

After giving the submit, you go to: make2.php

//Dê var_dump no arquivo fazer2.php
var_dump($_POST); //irá mostrar os valores disponíveis do formulário 1

Now do not do 2.php do this:

<input type="tipo_do_seu_input" name="nome_do_input" value="$_POST['valores_desejados_do_primeiro_formulario']">

- Now the user is going to fill form 2 - giving the submit, inside the make2.php , goes to your mysql code

Note: I know you want a session, but it is not recommended (by me: D) for this, my tip is easier. Until!

    
30.01.2017 / 21:53