这个最好放在客户端判断:
<form action="111.php" method="post" name= form1>
<input type="text" name="name">
<input type="password" name="pass">
<input type="button" name="press" onclick = sub()>
</form>
<script language = javascript>
function sub()
{
if (document.all.name.value =='')
{
alert("姓名不能为空");
return false;
}
if (document.all.pass.value =='')
{
alert("密码不能为空");
return false;
}
form1.submit();}
</script>
<form action="111.php" method="post" name= form1>
<input type="text" name="name">
<input type="password" name="pass">
<input type="button" name="press" onclick = sub()>
</form>
<script language = javascript>
function sub()
{
if (document.all.name.value =='')
{
alert("姓名不能为空");
return false;
}
if (document.all.pass.value =='')
{
alert("密码不能为空");
return false;
}
form1.submit();}
</script>
<html>
<head>
</head>
<body>
<?
extract($HTTP_POST_VARS); // 加上这一句
if($name==""){
echo "姓名不能为空"."<br>";
die();
}
if($pass==""){
echo "密码不能为空"."<br>";
die();
}
echo "成功"
?>
</body>
</html>
当然,友好的页面这种判断最好在客户端进行。
$_POST['变量名']
访问通过post方式传递的表单数据,这是为了和页面变量冲突