echo "<script>
alert('There are no fields to generate a report');
window.location.href='admin/ahm/panel';
</script>";
and get rid of redirect line below.
You were mixing up two different worlds.
Answer from Prasanth on Stack Overflowecho "<script>
alert('There are no fields to generate a report');
window.location.href='admin/ahm/panel';
</script>";
and get rid of redirect line below.
You were mixing up two different worlds.
use this code to redirect the page
echo "<script>alert('There are no fields to generate a report');document.location='admin/ahm/panel'</script>";
You can't do it that way. PHP header must sent out before any content, so the correct order is:
header("location: login6.php");
echo "Please Log In First";
But these codes will redirect instantly and wouldn't let you see the content. So I would do the redirection by JavaScript:
echo "Please Log In First";
echo "<script>setTimeout(\"location.href = 'http://www.example.com';\",1500);</script>";
You can use header refresh. It will wait for specified time before redirecting. You can display your message then.
header( "refresh:5; url=login.php" ); //wait for 5 seconds before redirecting
PHP's redirection with header("Location:xxx.php"); functionality does not allow any browser output.
You can use Javascript redirection (taking in consideration of program logic).
echo '<script>
alert(' + '"Welcome ' + $uname .'");
window.location.href="welcome.php";
</script>';
echo '<script type="text/javascript">';
echo 'alert("Welcome $uname");';
echo 'window.location.href = "index.php";';
echo '</script>';
try upper instead of below code
``echo "<script> alert('Welcome $uname')</script>";
``header("location: dashboard.php");
Header( 'Location: Database.php?success=1' );
And in the Database.php page :
if ( isset($_GET['success']) && $_GET['success'] == 1 )
{
// treat the succes case ex:
echo "Success";
}
Store it in the session as sort of a "flash"-message:
$_SESSION['message'] = 'success';
and show it in Database.php after the redirect. Also delete its content after displaying it:
print $_SESSION['message'];
$_SESSION['message'] = null;
The advantage of this is, that the message won't be shown again every time the user refreshes the page.
Do something like
header("Location: index.php?Message=" . urlencode($Message));
Then on index.php...
if (isset($_GET['Message'])) {
print $_GET['Message'];
}
In other words, index.php will always check if it's being passed a message in the url. If there is one, display it. Then, just pass the message in the redirect
if you really want to use a modal popup, generate the js...
if (isset($_GET['Message'])) {
print '<script type="text/javascript">alert("' . $_GET['Message'] . '");</script>';
}
Note that this will break if you use quotes in the message unless you escape them
<script type="text/javascript">
alert("YOUR MESSAGE HERE");
location="REDIRECTION_PAGE.php";
</script>
Here is code that does exactely what you want (according to your title):
<script type="text/javascript">alert("Stupid message");history.go(-1);</script>
I don't like this way of working, you'd better to use sessions, or creating one file that displays the form and does the validating.
@M LOHIT
<script type="text/javascript">alert("Stupid message");window.location.href='previouspage';
</script>
This will surely work for you