我最近使用php为我的网站开发了一个登录注册表单,但却出现了以下错误。
Notice: Undefined index: action in C:\xampp\htdocs\login\login.php on line 3
Notice: Undefined index: reg in C:\xampp\htdocs\login\login.php on line 24
Notice: Undefined index: action in C:\xampp\htdocs\login\login.php on line 29
Notice: Undefined index: msg in C:\xampp\htdocs\login\login.php on line 40
这段代码工作正常并从数据库发送和检索数据,但我真的不知道他为什么给我这些错误。下面是代码
<?php
require_once('load.php');
if ( $_GET['action'] == 'logout' ) {
$loggedout = $j->logout();
}
$logged = $j->login('index.php');
?>
<html>
<head>
<title>Login Form</title>
<style type="text/css">
body { background: #c7c7c7;}
</style>
</head>
<body>
<div style="width: 960px; background: #fff; border: 1px solid #e4e4e4; padding: 20px; margin: 10px auto;">
<?php if ( $logged == 'invalid' ) : ?>
<p style="background: #e49a9a; border: 1px solid #c05555; padding: 7px 10px;">
The username password combination you entered is incorrect. Please try again.
</p>
<?php endif; ?>
<?php if ( $_GET['reg'] == 'true' ) : ?>
<p style="background: #fef1b5; border: 1px solid #eedc82; padding: 7px 10px;">
Your registration was successful, please login below.
</p>
<?php endif; ?>
<?php if ( $_GET['action'] == 'logout' ) : ?>
<?php if ( $loggedout == true ) : ?>
<p style="background: #fef1b5; border: 1px solid #eedc82; padding: 7px 10px;">
You have been successfully logged out.
</p>
<?php else: ?>
<p style="background: #e49a9a; border: 1px solid #c05555; padding: 7px 10px;">
There was a problem logging you out.
</p>
<?php endif; ?>
<?php endif; ?>
<?php if ( $_GET['msg'] == 'login' ) : ?>
<p style="background: #e49a9a; border: 1px solid #c05555; padding: 7px 10px;">
You must log in to view this content. Please log in below.
</p>
<?php endif; ?>
<h3>Login</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
<p>Not a member? <a href="register.php">Register here</a></p>
</div>
</body>
</html>
答案 0 :(得分:2)
您发送的表单为POST
,但您的内容为GET
,您应该将表单的操作更改为GET
,或者从{{1}检索您的数据而不是$_POST
。
你可以改变:
$_GET
要:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
或将您的所有<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
更改为$_GET