Return to the registration screen

0

I'm a beginner in PHP and need some help.

I have a cadastre.html that has some fields that calls the cadastre.php that inserts the data in the database and shows the message if it was inserted successfully or not.

How do I display this message on the registration screen?

I'm trying to do this, when I click the "Register" button it goes to the cadastre.php and returns to the cadastre.html with the return message (if it was inserted in the database or if it was inserted successfully ).

Does anyone have any light to help me?

    
asked by anonymous 20.11.2018 / 04:55

4 answers

1

I think you want to make it show a message when it was inserted, you can do so

echo '<script> alert ("Quantidade alterada com sucesso!"); location.href=("cadastro.php")</script>';
    
20.11.2018 / 11:46
0

Replace everything with a .php page, so you can work your html and php in a single file.

ex.:

<?php

if(count($_POST)){
$variavel = $POST["variavel"];

//sua requisição via banco de dados

//se for ok, você retorna a mensagem
}

?>

//seu codigo html aqui

Any doubts put the files here

    
20.11.2018 / 05:07
0

A HTML file is static, you can not mount it using information you got in PHP . For this you need a template engine , that by chance, PHP is already one.

For organization purposes, you'd better have something like cadastro_controller.php and cadastro.php . A PHP file can contain both PHP code and HTML, so you can use cadastro.php to mount your HTML, and access the PHP message simultaneously.

I'd like to write how to do this here, but honestly, the process is not so trivial. You can use require "controler.php" within cadastro_controller.php to bring your page to the environment where you have access to the register result, but this is a hack that does not scale well in large projects. It is possible to use frameworks for this process, Laravel and CodeIgnater are quite popular.

At the end of the process, you will have your registration.php similar to

<html>
...
<p><?= $menssagem ?></p>
<a>Clique aqui para realizar um novo cadastro</a>
<a>Clique aqui para listar os automóveis</a>
...
</html>
    
20.11.2018 / 05:41
0

Create your form page as a php file: cadastro.php Submit the form information to another php page: register-insere.php for example On the register-insert.php page, send the information to the database. Make an insert check and insert a successful message session.

session_start();

if(cadastroInserido()){
  $_SESSION['inserido']="Cadastro inserido com sucesso!";
}

Then create a header to return to the registration page.php

header("location:cadastro.php);
die();

on the registration page.php read the session and then unbind it

if(isset($_SESSION['inserido'])){
echo $_SESSION['inserido'];
unset($_SESSION['inserido']);
}

I think it's one of the ways to do

    
20.11.2018 / 12:04