matthew s matthew s - 5 days ago 6
Javascript Question

Alert wont display with location

im trying to get error codes to generate with JS so that i dont have to use die. Im using the location function to refresh the page then create the alert but it wont display. It goes as follows:

header("Location: register.php");
$fields = "You did not complete all the required fields. Please try again.";
echo "<script type='text/javascript'>alert('$fields');</script>";

Answer
header("Location: register.php");

You instructed a location change before any outputs. Outputs will always be ignored in this case.

You may use:

header("Refresh: 10;url=register.php")
Comments