嗨,我有这个令人讨厌的错误,我似乎无法修复......第182行是
alert('Successfully Updated');
在上下文中,代码看起来像这样,
if (mail($to, $subject, $body, $headers)) {
echo '<script type = "text/javascript" >
alert('Successfully Updated');
window.location.href='contact.html';
</script>';
} else {
echo 'An unexpected error has occurred.';
}
有人能发现错误吗?
答案 0 :(得分:5)
由于语法高亮显示器清楚地显示您有引用问题:
echo '<script type = "text/javascript" >
alert('Successfully Updated');
window.location.href='contact.html';
</script>';
应该(或者可能是,因为有几个修复)
echo '<script type = "text/javascript" >
alert("Successfully Updated");
window.location.href="contact.html";
</script>';
您使用单引号('
)表示两种不同的东西:
PHP只知道(1)所以认为你想要回应的字符串在alert(
之后立即结束。
答案 1 :(得分:2)
if (mail($to, $subject, $body, $headers)) {
echo '<script type = "text/javascript" >
alert(\'Successfully Updated\');
window.location.href=\'contact.html\';
</script>';
} else {
echo 'An unexpected error has occurred.';
}