if(!empty($msg)){
    echo "<script>";
    echo "    alert(".$msg.");";
    echo "</script>";
}
应该这样吧