This worked brilliantly for me, :
$query = "INSERT INTO `table` (...or put your preferred sql stuff)"
$result = mysqli_query($connect, $query);
if($result){
// If everything runs fine with your sql query you will see a message and then the window
//closes
echo '<script language="javascript">';
echo 'alert("Successful!")';
echo '</script>';
echo "<script>window.close();</script>";
}
else {
echo '<script language="javascript">';
echo 'alert("Problem with database or something!")';
echo '</script>';
}