I want to display an alert box showing a message with PHP.
我想要显示一个警告框,显示带有PHP的消息。
Here is my PHP code:
这是我的PHP代码:
<?php
header("Location:form.php");
echo '<script language="javascript">';
echo 'alert(message successfully sent)'; //not showing an alert box.
echo '</script>';
exit;
?>
But it is not working.
但它不起作用。
11 个解决方案
#1
102
use this code
使用这个代码
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
The problem was:
问题是:
- you missed
"
- 你错过了”
- It should be
alert
notalery
- 它应该保持警惕。
#2
13
Try this:
试试这个:
Define a funciton:
定义一个函数:
<?php
function phpAlert($msg) {
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}
?>
Call it like this:
叫它是这样的:
<?php phpAlert( "Hello world!\\n\\nPHP has got an Alert Box" ); ?>
#3
4
There is a syntax error (typo):
有一个语法错误(typo):
It's alert
not alery
.
不是alery的警报。
#4
3
echo '<script language="javascript>';
Seems like a simple typo. You're missing a double-quote.
看起来是一个简单的错误。你错失了一个双引号。
echo '<script language="javascript">';
This should do.
这个应该做的。
#5
2
change your output from
改变你的输出
echo '<script language="javascript>';
to
来
echo '<script type="text/javascript">';
you forgot double quotes... and use the type tag
你忘了双引号……使用类型标签。
#6
2
I don't know about php but i belive the problem is from this :
我不知道php,但我相信问题是这样的:
echo '<script language="javascript>';
echo 'alery("message successfully sent")';
echo '</script>';
Try to change this with :
试着改变一下:
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
#7
2
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
#8
2
When I just run this as a page
当我把它作为一个页面运行时。
<?php
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
exit;
it works fine.
它将正常工作。
What version of PHP are you running?
您运行的是什么版本的PHP ?
Could you try echoing something else after: $testObject->split_for_sms($Chat);
您可以试着重复其他的东西:$testObject->split_for_sms($Chat);
Maybe it doesn't get to that part of the code? You could also try these with the other function calls to check where your program stops/is getting to.
也许它没有达到代码的那一部分?您也可以尝试使用其他函数调用来检查程序在哪里停止。
Hope you get a bit further with this.
希望你能更进一步。
#9
-2
When you use javascript tag in echo function, It can be misleading because of "quotation" signs in php echo function. I suggest you to close tag!
当您在echo函数中使用javascript标记时,由于php echo函数中的“引号”符号,它可能会产生误导。我建议你关闭标签!
<?php
header("Location:form.php");
?>
<script type="text/javascript">
alert("message successfully sent");
</script>
<?php
exit;
?>
#10
-3
echo "<script>alert('same message');</script>";
This may help.
这可能有帮助。
#11
-6
imposible !! use ajax to show that . or use fake alert box .
不现实! !使用ajax来显示这一点。或者使用假警报框。
simple code.
简单的代码。
<style>
#myalert{
display:none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
text-align: center;
z-index: 1000;
background-color: rgba(0,0,0, .5);
}
#myalert div{
width: 500px;
margin: 200px auto;
background: #fff;
padding: 0px;
text-align: left;
overflow: hidden;
}
</style>
Show or Hide alert in php.
在php中显示或隐藏警报。
<?php
$display="block";
$msg="This is Alert";
?>
and in your HTML.
和在你的HTML。
<div id="myalert" style="display:<?php echo $display ?>;">
<div><?php echo $msg; ?></div>
</div>
#1
102
use this code
使用这个代码
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
The problem was:
问题是:
- you missed
"
- 你错过了”
- It should be
alert
notalery
- 它应该保持警惕。
#2
13
Try this:
试试这个:
Define a funciton:
定义一个函数:
<?php
function phpAlert($msg) {
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}
?>
Call it like this:
叫它是这样的:
<?php phpAlert( "Hello world!\\n\\nPHP has got an Alert Box" ); ?>
#3
4
There is a syntax error (typo):
有一个语法错误(typo):
It's alert
not alery
.
不是alery的警报。
#4
3
echo '<script language="javascript>';
Seems like a simple typo. You're missing a double-quote.
看起来是一个简单的错误。你错失了一个双引号。
echo '<script language="javascript">';
This should do.
这个应该做的。
#5
2
change your output from
改变你的输出
echo '<script language="javascript>';
to
来
echo '<script type="text/javascript">';
you forgot double quotes... and use the type tag
你忘了双引号……使用类型标签。
#6
2
I don't know about php but i belive the problem is from this :
我不知道php,但我相信问题是这样的:
echo '<script language="javascript>';
echo 'alery("message successfully sent")';
echo '</script>';
Try to change this with :
试着改变一下:
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
#7
2
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
#8
2
When I just run this as a page
当我把它作为一个页面运行时。
<?php
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
exit;
it works fine.
它将正常工作。
What version of PHP are you running?
您运行的是什么版本的PHP ?
Could you try echoing something else after: $testObject->split_for_sms($Chat);
您可以试着重复其他的东西:$testObject->split_for_sms($Chat);
Maybe it doesn't get to that part of the code? You could also try these with the other function calls to check where your program stops/is getting to.
也许它没有达到代码的那一部分?您也可以尝试使用其他函数调用来检查程序在哪里停止。
Hope you get a bit further with this.
希望你能更进一步。
#9
-2
When you use javascript tag in echo function, It can be misleading because of "quotation" signs in php echo function. I suggest you to close tag!
当您在echo函数中使用javascript标记时,由于php echo函数中的“引号”符号,它可能会产生误导。我建议你关闭标签!
<?php
header("Location:form.php");
?>
<script type="text/javascript">
alert("message successfully sent");
</script>
<?php
exit;
?>
#10
-3
echo "<script>alert('same message');</script>";
This may help.
这可能有帮助。
#11
-6
imposible !! use ajax to show that . or use fake alert box .
不现实! !使用ajax来显示这一点。或者使用假警报框。
simple code.
简单的代码。
<style>
#myalert{
display:none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
text-align: center;
z-index: 1000;
background-color: rgba(0,0,0, .5);
}
#myalert div{
width: 500px;
margin: 200px auto;
background: #fff;
padding: 0px;
text-align: left;
overflow: hidden;
}
</style>
Show or Hide alert in php.
在php中显示或隐藏警报。
<?php
$display="block";
$msg="This is Alert";
?>
and in your HTML.
和在你的HTML。
<div id="myalert" style="display:<?php echo $display ?>;">
<div><?php echo $msg; ?></div>
</div>