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're missing semi-colons after your javascript lines. Also, window.location should have .href or .replace etc to redirect - See this post for more information.
echo '<script type="text/javascript">';
echo 'alert("review your answer");';
echo 'window.location.href = "index.php";';
echo '</script>';
For clarity, try leaving PHP tags for this:
?>
<script type="text/javascript">
alert("review your answer");
window.location.href = "index.php";
</script>
<?php
NOTE: semi colons on seperate lines are optional, but encouraged - however as in the comments below, PHP won't break lines in the first example here but will in the second, so semi-colons are required in the first example.
if (window.confirm('Really go to another page?'))
{
alert('message');
window.location = '/some/url';
}
else
{
die();
}
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>
Alert will block the program flow so you can just write the following.
echo ("<script LANGUAGE='JavaScript'>
window.alert('Succesfully Updated');
window.location.href='http://someplace.com';
</script>");
You could do this:
echo "<script>alert('Successfully Updated'); window.location = './edit.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
Using a javascript alert is going to delay the redirect until the user clicks OK. What you probably want to do is display the alert in your index.php when there has been a successful subscription. There are a few different ways of passing this information but the most common way is to pass the success message in the session.
// page1.php
<?php
session_start();
if($conn->query($sql)===TRUE){
$_SESSION['message'] = "Registration successful";
header('Location: index.php');
exit();
}
session_write_close ();
?>
// index.php
<?php
session_start();
if (isset($_SESSION['message'])) {
$show_message = $_SESSION['message'];
$_SESSION['message'] = null;
}
session_write_close ();
// ...
if (isset($show_message)) {
echo "<script>alert('{$show_message}');</script>";
}
Other alternatives are to pass the data in the URL such as index.php?message=Registration%20Successful or passing the message in a cookie.
you can print message in alert and redirect as below:
echo "<script>alert('Success');document.location='index.php'</script>";
In your code you already send something as echo so you cannot use header after that.