Kindly go though the link I want to show an alert message. My insertion is successful and the header also works fine but alert()
is not working. Any help would be appreciated.
if(mysql_query($query))//query execution
{
echo '<script language="javascript" type="text/javascript"> ';
echo 'alert("message successfully Inserted")';//msg
echo '</script>';
header('location:madesignin.php');//header jump to the page
exit;
}
else//data will be not inserted if condition fails
{
echo "DATA NOT INSERTED";
}
try this code:
if(mysql_query($query))//query execution
{
echo '<script language="javascript" type="text/javascript">
alert("message successfully Inserted");
window.location = "madesign.php";
</script>';
}
else
{
echo 'DATA INSERTED';
}
alert("message successfully Inserted"); window.location = "madesign.php";
Alert will not work in above situation because redirecting and javascript alert() is calling same time. So it will skip javascript and redirect to page.
Try
if(mysql_query($query))//query execution
{
echo '<script language="javascript" type="text/javascript"> ';
echo 'if(!alert("message successfully Inserted")) {';//msg
echo ' location.href="madesignin.php"';
echo '}';
echo '</script>';
exit;
}
else//data will be not inserted if condition fails
{
echo "DATA NOT INSERTED";
}
You may not need to use Javascript alert. There's a way to send a message after redirecting to a new page using php.
header("location: thank_you.php?success_message=thanks for shopping with us");
if the statement doesn't run;
else{
header("location: index.php");
}
exit;
then in the new page called thank_you.php for example, you should display the message;
<?php if (isset($_GET['success_message'])){ ?>
<h3 style="color: gold"><?php echo $_GET['success_message']; ?></h3>
<?php } ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.