提交If语句未定义错误

时间:2013-11-13 13:26:19

标签: php

我遇到以下问题:if($ _POST ['Submitted'] ==“true”){此行一直产生未定义的错误“未定义的索引:在C:\ wamp \ www \ oop_settings \ index中提交第13行的.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

?> 

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

if (isset($_POST['Submitted']) && $_POST['Submitted'] == "true") {

答案 2 :(得分:0)

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

例如:

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

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