用个方法
function Notice($alert,$url){
echo "<script language='javascript'>";
echo "alert('".$alert."');";
echo "location.href='".$url."';";
echo "</script>";}
$username=$_POST['username'];
if(empty($username))
Notice("不能为空","test.php");
else{
echo $username;