为什么在同一页面无法传值,且提示错误

为什么在同一页面无法传值,且提示错误

请教各位高手了,不明白为什么,谢谢了.我制作了一个用户登陆程序,首页是index.php,并且想在首页进行用户登陆的验证,为什么将用户名和密码传回首页就提示我用户名和密码未定义呢?·
<?php
                if($_POST['keep_log']!=''){
                                session_set_cookie_params(365*24*3600);
                                
                                }else{
                                
                                session_set_cookie_params(0);
                        }
                                       
                require_once("DB\DbAccess.php");
                $username = trim($_POST['username']);
                $pwd = md5($_POST['pwd']);
                $errmsg = '';
                if(!empty($username)){
                        if(empty($username)){
                        
                                $errmsg = 'error.';
                        }
                        if(empty($errmsg)){
                        
                                $db = new mysql;
                                $db->connect();
                                $sql = "SELECT * FROM t_member WHERE username = '".$username."' AND passwd ='".$pwd."'";
                                $result = $db ->query($sql);                        
                                
                                if($result&&$result->numrows>0){
                                        session_start();
                                        $_SESSION['uid'] = $username;
                                        header("Location:login.php?username=$username");
                                       
                                }else{
                                
                                        $errmsg = "";        
                                
                                }
                                
                        }               
               
                }        
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>hello</title>
</head>
<body>
<form name="login" action="index.php" method="post">
<tr><td colspan="2" align="center" class="alert"></td></tr>
<tr><?=$errmsg?>
        <td>ID:</td>
    <td><input name="username" type="text"/></td>
</tr>
<tr><td>password:</td>
    <td><input name="pwd" type="password" id="pwd"/></td>
</tr>
<tr><td colspan="2" align="center">

    <input type="submit" name="submit" value="Login">  

    <input type="reset" name="submit" value="Cancel">

    </td>

</tr>
<tr>
        <td>
                <input type="checkbox" name="keep_log"/>下回不用登陆
        </td>
</tr>

</form>
提示错误
Notice: Undefined index: keep_log in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\shopping\index.php on line 2

Notice: Undefined index: username in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\shopping\index.php on line 10

Notice: Undefined index: pwd in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\shopping\index.php on line 11

[ 本帖最后由 duke 于 2009-1-29 17:17 编辑 ]

这个变量$_POST['keep_log']是提交了表单才有的。浏览这个页面而没有提交这个变量是不存在的。所以会提示出错。应该这样写
if(isset($_POST['keep_log']) && $_POST['keep_log']!=''){
如履薄冰

谢谢您的回复,但是我这样修改完毕,在数据库中取得用户名时,无法得到了。我在句首加了一个errorreporting(0);该错误就不再提示了。