0

So I got data entry that ends with a header to a location (index.php), wanted to set a var $successMsg = "Good";

and to display it on the index.php page.

 if (mysqli_query($conn, $insertData)) {
   $successMsg = "Good";
   header("Location: ../index.php?success");
} else {
    header("Location: ../index.php?failed");
}
mysqli_close($conn);

That way on index.php it will echo $successMsg

Dharman
  • 30,962
  • 25
  • 85
  • 135
talElm
  • 5
  • 3

1 Answers1

0

You can send the message as a GET variable

if you use the following instead of the above

 if (mysqli_query($conn, $insertData)) {
   $successMsg = "Good";
   header("Location: ../index.php?success_msg=$successMsg&status=success");
} else {
    header("Location: ../index.php?success_msg=$successMsg&status=failed");
}

then in index.php you have the variable in the $_GET array

echo $_GET['success_msg'];
Nathanael
  • 870
  • 5
  • 11