我在以下方面有问题:if ($_POST['已提交'] == "true") { 此行不断产生未定义的错误"未定义的索引:在第 13 行以 C:''wamp''www''oop_settings''index.php 提交
<?php
session_start();
ob_start();
include_once ("includes/settings.php");
include("includes/functions/functions.php");
//include_once ("includes/optional.php");
var_dump($_POST);// Sanity check
if ($_POST['Submitted'] == "true") {
$Errors = "";
$_SESSION['LoggedIn'] = false;
$_SESSION['UserID'] = "";
$_SESSION['UserAdmin'] = false;
// process submitted data
$userSQL = $Database->Execute("SELECT UserID, UserFullname, UserEmail, UserLastPassword FROM Users WHERE UserName = '" . mysql_real_escape_string($Text->ValidSQLString($_POST['Username'])) . "' AND UserPassword = '" . md5($_POST['Password']) . "' AND UserActive = 1 AND UserListingOnly = 0 AND UserID NOT IN (61)");
$UserCount = $Database->RecordCount($userSQL);
//echo $userSQL;
if ($UserCount == 1) {
// user found
$rowUser = $Database->Records($userSQL);
$LastMonth = date("Y-m-d", mktime(0, 0, 0, (date("m") - 1), date("d"), date("Y")));
if ($rowUser['UserLastPassword'] <= $LastMonth) {
// password expired, generate new password
$Errors = "Your password has expired, your new password has been sent to your inbox.";
$NewPassword = $Text->ResetPassword();
$userpasswordSQL = "UPDATE Users SET UserPassword = '" . md5($NewPassword) . "', UserLastPassword = '" . date("Y-m-d") . "' WHERE UserID = " . $rowUser['UserID'];
$dbUserPassword = $Database->Execute($userpasswordSQL) or die ("New Password Query Failed: " . mysql_error());
mail($rowUser['UserEmail'], "Watkins Hire - Your New Password", "Your old password has expired for security reasons.'n'nYour new password is: $NewPassword", "From: password@watkinshire.co.uk");
}// end UserCount
}//end if
}//end if
else {
// valid log in
$_SESSION['LoggedIn'] = true;
$_SESSION['UserID'] = $rowUser['UserID'];
LoginForm(); // call the form function
}// end else if
?>
POST 请求没有索引"已提交",这就是为什么 PHP 告诉你它是未定义的。
如注释所示,您应该首先使用 isset()
测试它来检查它是否存在,然后验证此索引的值。
那是
因为它还不存在。如果只需要设置isset()
,请使用 ,如果要确保值不是空字符串,请使用 !empty()
,0
或null
检查值。
if (isset($_POST['Submitted']) && $_POST['Submitted'] == "true") {
检查表单提交名称 $_POST['submitted']
- submitted
应该是提交名称的名称
例如:
<form>
<input type="submit" name="submitted">
</form>
应该是这样的事情吧。