0

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";">&times;</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";">&times;</span> ';
echo 'Your messaage has been sent ';
echo '    </div>';

1 Answer 1

2

This line has too many nested " marks:

echo ' <span class="closebtn" onclick="this.parentElement.style.display="none";">&times;</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';">&times;</span> 
      Your messaage has been sent 
    </div>
 <?php
 }else{
Sign up to request clarification or add additional context in comments.

8 Comments

can you edit y code properly, because your answer's code make an error for me :(
syntax error, unexpected 'none' (T_STRING), expecting ',' or ';' in C:\wamp\www\
if you can please edit my code properly,thank you very much
Updated. Just forgot to remove one of the '; for the closing </div>
Thank you very much :D its working fine now :) and I have a question. why use php tags like this ?> <?php
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.