0

我有以下问题: if ($_POST['Submitted'] == "true") { 此行不断产生未定义的错误“未定义的索引:在 C:\wamp\www\oop_settings\index.php 上提交第 13 行

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

?> 
4

3 回答 3

0

检查您的表单提交名称$_POST['submitted']-submitted应该是您提交名称的名称

例如:

<form>
 <input type="submit" name="submitted">
</form>

应该是这样的............

于 2013-11-13T13:33:42.990 回答
0

POST 请求没有索引“已提交”,这就是 PHP 告诉您它未定义的原因。

就像评论一样,您应该首先通过对其进行测试来检查它的存在isset(),然后验证该索引的值。

于 2013-11-13T13:28:55.903 回答
0

那是因为它还不存在。如果isset()您只是需要设置它,或者!empty()如果您想确保该值不是空字符串,0或者null在检查值之前使用。:

if (isset($_POST['Submitted']) && $_POST['Submitted'] == "true") {
于 2013-11-13T13:30:06.470 回答