这是我的php
代码。插入数据后,我使用了警告信息。消息显示正确。但是当我点击 x
十字标志时,它就不会关闭。
if(isset($_POST['create_post'])){
$name = $_POST['name'];
$email = $_POST['email'];
$country = $_POST['country'];
$msg = $_POST['description'];
$stmt = $connection->prepare("INSERT INTO message(name,email,country,msg,date) VALUES (?, ?, ?, ?,now())");
$stmt->bind_param('ssss', $name,$email,$country,$msg);
$stmt->execute();
$stmt->close();
if($stmt){
echo '<div class= "alert">';
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">×</span> ';
echo 'Your messaage has been sent ';
echo ' </div>';
}else{
die('Query fialed' . mysqli_error($connection));
}
}
警报信息部分:
echo '<div class= "alert">';
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">×</span> ';
echo 'Your messaage has been sent ';
echo ' </div>';
答案 0 :(得分:2)
这一行有太多嵌套的"
标记:
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">×</span> ';
如果你正确地逃避了内部的那些(\"
)它将起作用。
使用原始HTML的小提琴示例:https://jsfiddle.net/myingling/3vv7jLd4/
更好的是,我只是删除了echo
语句,所以它看起来像这样:
if($stmt){
?>
<div class= "alert">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
Your messaage has been sent
</div>
<?php
}else{