0

我有一个 login.php 页面

<!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>

还有我的 register.php 页面

<?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>

但是当我在登录页面中单击注册时出现错误

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

我的问题首先是我缺少什么,其次是这个错误的含义是什么。因为我已经看过很多次了。

4

2 回答 2

3

这不是错误,而是通知。它告诉您$_POST['submit']etc 没有填写,这是有道理的,因为您没有向他们发布任何内容。

于 2013-08-06T17:17:31.373 回答
0

首先检查表单是否已提交,然后进行处理。

<?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");
}
?>
于 2013-08-06T17:28:39.427 回答