Reputation: 41
Kindly go though the linkI 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";
}
Upvotes: 0
Views: 9445
Reputation: 3
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 } ?>
Upvotes: 0
Reputation: 1483
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";
Upvotes: 2
Reputation: 1436
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";
}
Upvotes: 0