dsvtnz6350
dsvtnz6350
2013-08-06 17:13
浏览 23
已采纳

未定义索引忽略错误抑制

I have a login.php page with

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Page</title>
<style type="text/css"> 
h2 {letter-spacing: 10px; font-size: .2in; background-color: #33CC00; color: #000000; text-transform:uppercase; width:260px}
span {color: #FF00CC}
legend {font-variant: small-caps; font-weight: bold}
fieldset {width: 260px; font-family: "Times New Roman", Times, serif; background-color: #CCCCCC; color: #000000}
label {display:block;}
.placeButtons {position: relative; left: 0px; width: 70px; margin: 5px; 0px;}
</style>
</head>

<body>
<h2>Login Page</h2>
<form name="loginform" action='successfullogin.php' method='POST'>
<fieldset>
<legend>Form</legend>
    <label>Username: <input type="text" name="username"/><span>*</span></label>    <br/>
    <label>Password: <input type="password" name="pass"/><span>*</span></label>
    <input class="placeButtons" type="reset" value='Reset'/>
    <input class="placeButtons" type="submit" value='Login'/>
    <a href='register.php'>Register</a>
</fieldset>
</form>
</body>
</html>

and also my register.php page

<?php
echo "Register";
$submit = $_POST['submit'];
$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = date("Y-m-d");
?>
<html>
<p>
<form action='register.php' method='POST'>
<table>
    <tr>
        <td>
        Your full name:
        </td>
        <td>
        <input type='text' name='fullname' value='<?php echo $fullname ?>'>
        </td>
    </tr>
    <tr>
        <td>
        Choose a username:
        </td>
        <td>
        <input type='text' name='username' value='<?php echo $username ?>'>
        </td>
    </tr>
    <tr>
        <td>
        Choose a password:
        </td>
        <td>
        <input type='password' name='password'>
        </td>
    </tr>
    <tr>
        <td>
        Repeat your password:
        </td>
        <td>
        <input type='password' name='repeatpassword'>
        </td>
    </tr>
</table>
<p>
<input type='submit' name='submit' value='Register'>
</p>
</form>
</html>

but when I click register in the login page I have the error

Notice: Undefined index: submit in C:\wamp\www\.... on line 3
Notice: Undefined index: fullname in C:\wamp\www\.... on line 4
Notice: Undefined index: username in C:\wamp\www\.... on line 5
Notice: Undefined index: password in C:\wamp\www\.... on line 6
Notice: Undefined index: repeatpassword in C:\wamp\www\.... on line 7

My question is first of all what I am missing and secondly what's the meaning of this error. Because I have seen it many times.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutui4649
    doutui4649 2013-08-06 17:28
    已采纳

    First check if the form is submitted then process it.

    <?php
    if( isset($_POST) ){
     $submit = $_POST['submit'];
     $fullname = strip_tags($_POST['fullname']);
     $username = strip_tags($_POST['username']);
     $password = strip_tags($_POST['password']);
     $repeatpassword = strip_tags($_POST['repeatpassword']);
     $date = date("Y-m-d");
    }
    ?>
    
    点赞 评论
  • doujing4555
    doujing4555 2013-08-06 17:17

    That's not an error, it's a notice. It's telling you that $_POST['submit'] etc aren't filled in, which makes sense, as you didn't POST anything to them.

    点赞 评论

相关推荐