0

为了简短起见:

我有一个单选按钮,但是当我提交表单时,它会给我以下通知:

注意:未定义索引:第 87 行 C:\xampp\htdocs\FDPW... 中的education_check

更多细节:

我有一个表单,其中有以下单选按钮:

              <div class="span11">
                    <h3>A.Education and Professional Qualifications Check:</h3>
                        <div class="span6">                                              
                       Education Checked?
                        </div>
                        <label class="radio">
                            <input id="education_check" name="education_check" value="1"  type="radio" <?php if(isset($_POST["education_check"])){ if($_POST["education_chec"]== "1"){ echo "checked"; }} ?> class="span1"> Yes
                        </label>
                        <label class="radio">
                            <input id="education_check" name="education_check" value="0"  type="radio" <?php if(isset($_POST["education_check"])){ if($_POST["education_check"]== "0"){ echo "checked"; }} ?>  class="span1"> No

                        </label>
                </div>

当我提交我的代码时,我有以下调用:

if(isset($_POST["submits"])) {
        $Message = helperFunctions::UpdateTableHrForms($id, $_POST["dob_city"], $_POST["dob_province"], $_POST["dob_country"],$_POST["education_check"]);
        $_POST["submits"] = null;
        echo $Message;
}

这是我在助手中的功能:

public static function UpdateTableHrForms(
    $id,$dob_city,$dob_province,$dob_country,$education_check) 
     {
    $conn = new mysqlcon();
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $query = "INSERT into `hr_forms` (`id`,`dob_city`,`dob_province`,`dob_country`,`education_check`)VLUES (:id,:dob_city,:dob_province,:dob_country,:education_check)";               
    try {
            if (helperFunctions::CheckIDExistHrForms($id) == 0) {
                $result = $conn->prepare($query);                                               
                $result->execute(array('id'=>$id,'dob_city'=>$dob_city,'dob_province'=>$dob_province,'dob_country'=>$dob_country,'education_check'=>$education_check));
                $Msg = "<div style=\"text-align:center;\" class=\"alert alert-success\">
                            <strong>Tips! </strong>
                                Data is successfully saved to database.
                            <button class=\"close\" data-dismiss=\"alert\" type=\"button\">&times;</button>
                        </div>";
            } else {
                $Msg = "<div style=\"text-align:center;\" class=\"alert alert-error\">
                            <strong>Error! </strong>
                                This employee's information is already existed in the system.
                            <button class=\"close\" data-dismiss=\"alert\" type=\"button\">&times;</button>
                        </div>";
            }
        } catch (Exception $e) {
            $e->getMessage();
            $Msg = $e; /* "<div style=\"text-align:center;\" class=\"alert alert-error\">
              <strong>Error! </strong>
              This associate information cannot save in the system.
              <button class=\"close\" data-dismiss=\"alert\" type=\"button\">&times;</button>
              </div>"; */
        }
    return $Msg;
}

但一直给我以下通知:

注意:未定义索引:第 87 行 C:\xampp\htdocs\FDPW... 中的education_check

4

2 回答 2

2

如果用户没有选中复选框,则该复选框没有发布的数据。所以:

$_POST["education_check"]- 不存在。

因此,您会收到“未定义索引”通知。

问题出在这一行:

$Message = helperFunctions::UpdateTableHrForms($id, $_POST["dob_city"], 
$_POST["dob_province"], $_POST["dob_country"],$_POST["education_check"]);

在表单上,​​在尝试访问发布的数据之前询问“isset”时,您的行为是正确的。

<?php if(isset($_POST["education_check"])){ if($_POST["education_chec"]== "1"){ echo 

(顺便说一句,您在该行的第二个条件中忘记了“k”)。

解决方案是:

$education_check = (isset($_POST['education_check'])) ? 1 : 0;

$Message = helperFunctions::UpdateTableHrForms($id, $_POST["dob_city"], 
$_POST["dob_province"], $_POST["dob_country"],$education_check);
于 2013-09-12T18:40:44.517 回答
0

未定义索引意味着当您引用变量education_check 时,它不存在......确保确实有数据被放入该变量中。

于 2013-09-12T18:40:31.730 回答