'I want to display a sweetalert after the inserting of data in my database

This is my php code of inserting data in mysql and displaying sweetalert after insertion but the sweetalert is not displayed.

<?php  
        if(isset($_POST['submit']))
        {
            $fullname=$_POST['txtFullName'];
            $email=$_POST['txtEmailId'];
            $contact=$_POST['txtContactNumber'];
            $msg=$_POST['txtMessage'];
            if($fullname!="" && $email!="" && $contact!="" && $contact!="")
            {
            $qry=mysql_query("insert into Contacts values('0','$fullname','$email','$contact','$msg')");
            mysql_query($qry) or die(mysql_error());    
            echo '<script type="text/javascript">
            myFn();
            </script>';
            }
        }
    ?>

This is the model through which I am inserting the data:

    <div id="fancy">
        <h2>Request information</h2>
        <form action="index.php" method="post" enctype="multipart/form-data" name="frmContact" id="frmContact">
            <input type="hidden" name="hdid" id="hdid" value="<?php echo isset($row["ContactId"])?$row["ContactId"]:"" ?>" />
            <div class="left">
                <fieldset class="name"><input placeholder="Full Name..." required="required" type="text" name="txtFullName" id="txtFullName"></fieldset>
                <fieldset class="mail"><input placeholder="Email address..." required="required" type="text" name="txtEmailId" id="txtEmailId"></fieldset>
                <fieldset class="name"><input placeholder="Contact Number" required="required" type="text" name="txtContactNumber" id="txtContactNumber"></fieldset>
            </div>
            <div class="right">
                <fieldset class="question"><textarea placeholder="Your Message..." required="required" name="txtMessage" id="txtMessage"></textarea></fieldset>
            </div>
            <div class="btn-holder">

                <button class="btn blue" type="submit" id="submit" name="submit">Send request</button>
            </div>
        </form>
    </div>

This is my function myFn

<script type="text/javascript">


    function myFn(){
        swal({ 
              title: "Success",
              text: "Thank you for contacting us. We will get back to you soon!",
              type: "success" 
        },
             function(){
                //event to perform on click of ok button of sweetalert
        });
    }

</script>

please help me to overcome this problem



Solution 1:[1]

Actually it's quite easy though, no need to create any function

Just do like this:

    echo "<script>
     swal({ 
      title: "Success",
      text: "Thank you for contacting us. We will get back to you soon!",
      type: "success" 
     });</script>"

Vote my answer plz, I really need a Reputation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adamakmar