I was trying to display a pop up message using sweet alert function after successful form data submission. My data is getting inserted into database but after successful insertion message including php variable($Name,$state) not displaying. If I use normal alert function it is working file.I asked this question at this forum previously Previous question asked and as per their recommendation i tried but no joy kindly help me to find out what is wrong in my code.
<?php
session_start();
error_reporting(0);
include('config.php');
if(isset($_POST['create']))
{
$Name=$_POST['Name'];
$state=$_POST['state'];
$sql="INSERT INTO  tblstudent(Name,state) VALUES('$Name','$state')";
$query = $dbh->prepare($sql);
echo $sql;
echo $Name;
echo $state;
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId)
{
    echo '
    <script>
        $(document).ready(function(){
            swal({
                title: "Successfully save! ${$Name}/${$state} ",
                html: "Your request for ${$Name}/${$state}  has been successfully filled",
                timer: 5000,
                timerProgressBar: true,
            }).then(function() {
                window.location = "index.php";
            });
        });
    
</script>
';
 
}
else 
{
$_SESSION['error']="Something went wrong. Please try again";
header('location:manage-region2.php');
}
}
?>
<!DOCTYPE html>
<html >
<head>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>  
</head>
<body>
<div class="panel-body">
<form role="form" method="post">
<div class="form-group">
<label>Name</label>
<input class="form-control" type="text" name="Name" autocomplete="off" required />
</div>
<div class="form-group">
<label>State Name</label>
<input class="form-control" type="text" name="state" autocomplete="off" required />
</div>
<button type="submit" name="create" class="btn btn-info">Create </button>
</form>
</div>
</body>
</html>
<?php  ?>
  
