This is my php code. after insert data, I am used alert message. Message appeared properly. but it not close when I click x cross sign.
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));
}
}
Alert message part:
echo '<div class= "alert">';
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">×</span> ';
echo 'Your messaage has been sent ';
echo ' </div>';
asked Jun 15, 2017 at 19:05
Rooter
3831 gold badge8 silver badges28 bronze badges
1 Answer 1
This line has too many nested " marks:
echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">×</span> ';
If you escape the inner ones properly (\") it will work.
Fiddle example by using raw HTML: https://jsfiddle.net/myingling/3vv7jLd4/
Better yet, I'd just remove the echo statements, so it looks like this:
if($stmt){
?>
<div class= "alert">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
Your messaage has been sent
</div>
<?php
}else{
answered Jun 15, 2017 at 19:09
Bing
3,1937 gold badges50 silver badges88 bronze badges
Sign up to request clarification or add additional context in comments.
8 Comments
Rooter
can you edit y code properly, because your answer's code make an error for me :(
Rooter
syntax error, unexpected 'none' (T_STRING), expecting ',' or ';' in C:\wamp\www\
Rooter
if you can please edit my code properly,thank you very much
Bing
Updated. Just forgot to remove one of the
'; for the closing </div>Rooter
Thank you very much :D its working fine now :) and I have a question. why use php tags like this ?> <?php
|
default