我创建了一个允许登录的页面。有一些其他页面用于连接数据库并在成功登录后重新编辑到另一个页面等等。无论如何,我使用的变量名为&# 34; $了rememberMe"检查是否选中了“记住我”复选框。问题是,当我输入错误的密码时,它会说,"注意:未定义的索引:记住在第30行和第34行的/home/stud/1/1520621/public_html/Car_Club_Task2/index.php中。我检查了第30行,这是$ rememberme变量的声明。
有什么建议吗?可能只是我缺少的东西!
<!DOCTYPE HTML>
<html>
<head>
<title>Midlands Car Club</title>
<link rel="stylesheet" type="text/css" href="styles.css" media="screen">
</head>
<div id="header">
<h1>Midlands Car Club Log-In</h1>
</div>
<?php
include 'connect.php';
//if logged in equals true (running loggedin function from connect.php page)
if(loggedin())
{
//redirects to welcome.php if logged in
header("Location: welcome.php");
//for browsers that don't allow redirect headers
exit();
}
// Has submit button been pressed?
if (isset($_POST['login']))
{
//get data
$username = $_POST['username'];
$password = $_POST['password'];
$rememberme = $_POST['rememberme'];
//if username AND password have been entered
if ($username&&$password)
{
//select all from Login table
$login = mysql_query("SELECT * FROM Login WHERE Username='$username'");
// can refer to particular coloumns. Creating array of all data found in above query
while($row = mysql_fetch_assoc($login))
{
//row equal to array - where it finds username in db, it finds password in that row because of column name
$db_password = $row['Password'];
if ($password==$db_password)
{
//create variable with value true (boolean)
$loginOK = TRUE;
}
else
{
//create variable with value false (boolean)
$loginOK = FALSE;
}
if ($loginOK==TRUE)
{
//if remember me selected
if ($rememberme=="on")
// set cookie with current time plus 48 hours (write time in seconds)
setcookie("username", $username, time()+7200);
// if remember me not selected
else if ($rememberme=="")
//value of session is equal to value of username
$_SESSION['username']=$username;
//redirect
header("Location: welcome.php");
//if header redirect is disabled in browser
exit();
}
else
{
die("Incorrect Username or Password");
}
}
}
else
{
// kill script
die("Please enter username and password");
}
}
?>
<body>
<div class="add">
<form method="POST" action="index.php">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="checkbox" name="rememberme">Remember Me<br>
<input type="submit" name="login" value="Log In">
</form>
</div>
</body>
</html>