[英]Alert using echo in php
請通過鏈接 go我想顯示一條警告消息。 我的插入成功,header 也工作正常,但alert()
不工作。 任何幫助,將不勝感激。
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";
}
試試這個代碼:
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";
在上述情況下,警報將無法正常工作,因為重定向和javascript alert()正在同時調用。 因此它將跳過javascript並重定向到頁面。
嘗試
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";
}
您可能不需要使用 Javascript 警報。 有一種方法可以在使用 php 重定向到新頁面后發送消息。
header("location: thank_you.php?success_message=thanks for shopping with us");
如果語句沒有運行;
else{
header("location: index.php");
}
exit;
然后在名為 thank_you.php 的新頁面中,您應該顯示消息;
<?php if (isset($_GET['success_message'])){ ?>
<h3 style="color: gold"><?php echo $_GET['success_message']; ?></h3>
<?php } ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.