Feedback to the user

0

I have a method in php that performs certain task and then I need to give a success / error feedback to the user and return to my index.php. This feedback can occur both before returning as in my own index.php. My current scenario is as follows:

$conexao->setSQL("INSERT INTO tab VALUES ('x');
$resultado = $conexao->Executar();  


$erroRegistros = $totalRegistros - $adicRegistros;

if(!$resultado){
   die("erro in uploading the file".  mysql_error());
} else{
    // FEEDBACK NECESSÁRIO E RETORNO AO MEU INDEX
    voltarIndex();
}    

In this class, there are only codes in php. Already in my index.php there are codes html, javascript and inclusive, php.

For questions, my backIndex () method follows below:

function voltarIndex() {
    header("Location: index.php");
}

Could anyone help me?

    
asked by anonymous 11.01.2018 / 14:10

1 answer

1

You can use XMLHttpRequest to make a request without leaving the page and at the end of it, display a message to the user; or you can use Sessions to save a message and when you return to index.php , display the message.

Example with Sessions:

add-register.php

<?php

session_start();

$conexao->setSQL("INSERT INTO tab VALUES ('x')");
$resultado = $conexao->Executar();  


$erroRegistros = $totalRegistros - $adicRegistros;

if(!$resultado){
    $_SESSION["feedback"] = "Erro in uploading the file" . mysql_error();
} else{
    $_SESSION["feedback"] = "Digite sua mensagem aqui";
}

voltarIndex();

index.php

<?php session_start(); ?>
<!DOCTYPE hml>
<html>
    <head>
        <title>Title of the document</title>
    </head>

    <body>
        Página inicial
        Diversos botões
        tabelas
        afins

        <div class="msg"><?php echo (isset($_SESSION["feedback"])) ? $_SESSION["feedback"]; unset($_SESSION["feedback"]) : "" ?></div>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </body>
</html>
  

Remembering that session_start(); should stay on top.

    
11.01.2018 / 14:21