在php中使用echo进行警报

时间:2016-02-25 07:05:23

标签: javascript php

Kindly go though the link我想显示一条提示消息。我的插入成功,标题也正常,但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";
}

2 个答案:

答案 0 :(得分:2)

试试这段代码:

#include<type_traits>
#include<iostream>

template<int s>
struct C;

template<>
struct C<1> {
    void fun() { std::cout<<"fun1"; }
};

template<>
struct C<2> {
    void fun() { std::cout<<"fun2"; }
};

int main() {
    C<1> c;
    c.fun();
}

&#13;
&#13;
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';
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

警报在上述情况下不起作用,因为重定向和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";
}