How to send values from two different forms to an Insert?

Asked

Viewed 53 times

0

I need to save in the Bank the ID of the event I want to register the presence of a particular student, but also need to save some other data, so I created a <?php if(!isset($_POST['evento'])):?> However I need to send the value of both my form that only "looks" where contain the event/ idevento, and the values I entered for the student’s presence. Here’s how this is the form code at the moment. What I would need to go through to send all these values at once?

<?php if(!isset($_POST['evento'])):?>
                    <form method="POST" >
                    <input type="hidden" name="evento" value="QQCOISA" hidden/>              
                    <h3>Nome do Evento</h3>
                    <select name="idevento">
                        <?php
                        include "conectar.php";
                        $sql = "SELECT * FROM evento";
                        $result = $conn->query($sql);
                        if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                                echo "<option value='".$row["idevento"]."'>".$row["noeve"]."</option>";
                                $idkappa = $row["idevento"];
                            }
                        } else {
                            echo "Sem eventos ativos";
                        }
                        $conn->close();
                        ?>
                    </select>
                    <input type="submit" value="Selecionar Evento"/>
                    <?php else: ?>
                     <form method="POST" action="input.php">
                    <input type="hidden" name="pagina" value="inserirReg" hidden/>
                    <input type="hidden" name="idevento" hidden/>          
                    <h3>Dia Evento</h3>
                    <select name="seqDia"> 
                        <?php
                        include "conectar.php";
                        $sql = "SELECT * FROM diaevento WHERE idevento=".$_POST["idevento"];
                        $result = $conn->query($sql);
                        if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                                echo "<option value='".$row["idevento"]."'>".$row["seqDia"]."</option>";
                            }
                        } else {
                            echo "Sem eventos ativos";
                        }
                        $conn->close();
                        ?>
                    </select>

EDIT: I didn’t see the need to put the end of the code<?php endif; ?>, because there are only a few other selects like the Event Day.

  • What is the need to have 2 forms? The tag form is not visible to the user, so you can send everything in just one request.

  • I already say that it is not possible to send both at the same time, but it is possible to make that when you finish sending one, the other is sent automatically.

  • Another thing I noticed is that in your code, you do not close the first form and already open the second one. And the first one does not have the attribute action.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.