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
  • 26,923
  • 21
  • 73
  • 125
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
  • 778
  • 4
  • 10