修改如下:
<?
if($name== "")
{
   header("Location:error.php?id=用户ID不能为空!");
}
if( $password == "" )
{
    header("Location:error.php?id=用户密码不能为空!");
}
?>
最好是用Javascript检测

解决方案 »

  1.   

    <?
    if ($name=="")
    {
       header("Location:error.php?id=用户ID不能为空!");
    }
    else if ($password=="" )
    {
        header("Location:error.php?id=用户密码不能为空!");
    }
    ?>
      

  2.   

    你的程序改为以下:只要一个文件 login.php
    把以下代码放到login.php文件的<head></head>中间
    <script language="javascript">
    <!--
    function CheckForm(theForm) {
    if (theForm.name.value=="") {
    alert("对不起,请输入您的登录帐号!");
    theForm.name.focus();
    return false;
    }
    if (theForm.passwd.value=="") {
    alert("对不起,请输入您的登录密码!");
    theForm.passwd.focus();
    return false;
    }
    return true;
    }
    // -->
    </script><form action="usersch.php" method="post"  onSubmit="return CheckForm(this)">
    <table width="32%" border="1" align="center">
      <tr><td align=middle width="30%">用户ID:</td><td width="56%"><INPUT id="name" name="name" type="text"></td></tr>
      <tr><td align=middle width="30%">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td><td width="56%"><INPUT id="password" name="passwd" type="password"></td></tr>
      <tr><td align=middle colspan="2"><INPUT id=submit1 name=submit1 type=submit value=登录>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT id=reset1 name=reset1 type=reset value=重填></td></tr>
    </table></form>
      

  3.   

    你的程序改为以下:只要一个文件 login.php
    把以下代码放到login.php文件的<head></head>中间
    <script language="javascript">
    <!--
    function CheckForm(theForm) {
    if (theForm.name.value=="") {
    alert("对不起,请输入您的登录帐号!");
    theForm.name.focus();
    return false;
    }
    if (theForm.passwd.value=="") {
    alert("对不起,请输入您的登录密码!");
    theForm.passwd.focus();
    return false;
    }
    return true;
    }
    // -->
    </script><form action="usersch.php" method="post"  onSubmit="return CheckForm(this)">
    <table width="32%" border="1" align="center">
      <tr><td align=middle width="30%">用户ID:</td><td width="56%"><INPUT id="name" name="name" type="text"></td></tr>
      <tr><td align=middle width="30%">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td><td width="56%"><INPUT id="password" name="passwd" type="password"></td></tr>
      <tr><td align=middle colspan="2"><INPUT id=submit1 name=submit1 type=submit value=登录>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT id=reset1 name=reset1 type=reset value=重填></td></tr>
    </table></form>