我已经定义了storedUsername和storedPassword,但仍然面临错误说明
注意:未定义的变量:第13行的C:\ xampp \ htdocs \ mongosample \ index.php中的storedUsername
<?php
include './connect.php';
if(($_SERVER["REQUEST_METHOD"]=="POST") && (!empty($_POST['username'])) && (!empty($_POST['password']))){
$postedUsername = $_POST['username'];
$postedPassword = $_POST['password'];
$userDatabaseFind = $database->Bcard->find(array('username' => $postedUsername, 'password' => $postedPassword));
foreach ($userDatabaseFind as $useFind){
$storedUsername = $useFind['username'];
$storedPassword = $useFind['password'];
}
if(($postedUsername == $storedUsername) && ($postedPassword == $storedPassword)){
header('location:welcome.php');
}
else{
echo 'Error';
}
} ?>
我知道,密码不应该以空白文本传递,所以请不要提及
答案 0 :(得分:-1)
您应该在foreach循环之前初始化变量
$storedUsername = '';
$storedPassword = '';
然后是你的foreach循环