PHP - Display correctly entered data message

Asked

Viewed 53 times

0

I’m having difficulty putting a message saying : Data entered successfully and then send to another page.

<?php
  include 'ligacao_pdo.php';

    $condutor = $_POST['condutor'];
    $carro = $_POST['carro'];
    $matricula = $_POST['matricula'];

 if (!$ligacao->query("INSERT INTO condutor (condutor, carro, matricula) VALUES ('$condutor', '$carro', '$matricula')"))

{
   echo"SUCESSO";
   header("location: add.php");

 }

1 answer

0

On the page that makes the insertion in the database, you save a session variable with the message, like this:

<?php
include 'ligacao_pdo.php';
session_start();
$condutor = $_POST['condutor'];
$carro = $_POST['carro'];
$matricula = $_POST['matricula'];

if (!$ligacao->query("INSERT INTO condutor (condutor, carro, matricula) VALUES ('$condutor', '$carro', '$matricula')"))
{
    $_SESSION['sucesso'] = "Dados salvos com sucesso!";
    header("location: add.php");
}
?>

And in add.php the page to which the user will be redirected:

<script>
    alert("<?= $_SESSION['sucesso'];?>");
</script>

Or just an echo:

<?= $_SESSION['sucesso']; ?>

forehead there.

  • I’m not being able to redirect to the add.php page

  • Does it give an error? Are in the same directory?

Browser other questions tagged

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