Insert data into MYSQL database by PHP with more than 1 screen

Asked

Viewed 26 times

-1

I have my index.php and can insert data in the database using html form, but I need several screens for this form or 3 screens, index.php, tela2.php and tela3.php how do I make only 1 insertion using a Ubmit button at the end of everything on the screen3.php but taking all the fields of the 3 screens and only 1 insertion as said? I am using the code below but it only does the insertion in the form fields on the same screen.

if(isset($_POST['acao'])){
    $nome = $_POST['nome'];
    $sobrenome = $_POST['sobrenome'];
    $momento_registro = date('Y-m-d H:i:s');

    $sql = $pdo->prepare("INSERT INTO `clientes` VALUES(null,?,?,?)");

    $sql->execute(array($nome,$sobrenome,$momento_registro));

    //echo 'Cliente inserido com sucesso!';
}

3 answers

0

One of the solutions, if you will only use PHP for lack of knowledge in another technology like Javascript to do this without refreshing the page, would create a form for each file.

In the form submission, through an input of type Submit, you save the data in a session and recover all this data in the last screen.

And makes the sent Insert $_SESSION['dados'] for your bank script.

Take an MVC course, do not invest in procedural code because it has already fallen into disuse. I learned to use a Life Laravel :)

0

Take a look here. https://codepen.io/piyushpd/pen/PooPByb and here https://bootsnipp.com/search?q=wizard . This is an example of a 'Form Wizard'. The code is all in your screen1.php but it seems to have several pages. Even if you do not want to use a 'Wizard form' I think the only way is to store each form in a session variable and then in the last form submission access the variables that were saved while submitting the 'old' Forms. Search by '''Wizard form' and you will find more information if you need.

0

There are two ways to do this using html and native php, the first of which is: You can pass the values from one form to the other and hide the values with Hidden, for example: and just do the insertion on screen 3. Or you can enter values in the first form, fill in the remaining fields with null, and on screen 2 and 3 do an update on this rewrite

Browser other questions tagged

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