0

短くするために:

ラジオボタンがありますが、フォームを送信すると、次の通知が表示されます。

注意: 未定義のインデックス: C:\xampp\htdocs\FDPW の education_check... 87 行目

詳細:

次のラジオボタンがあるフォームがあります。

              <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;
}

しかし、私に次の通知を出し続けます:

注意: 未定義のインデックス: C:\xampp\htdocs\FDPW の education_check... 87 行目

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 

(ところで、その行の2番目の条件で「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 に答える