为什么我的代码会给出错误通知?注意:未定义索引:subject02在线

时间:2019-04-09 09:27:27

标签: php xampp

我收到未定义的索引错误,并且无法缓解此错误。

<?php include "htmlStart.php";?>

<div class="homeContent uk-padding-small adminHome">
  <form name="AddTeacherForm" action="" method="post">
    <fieldset class="uk-fieldset uk-text-center">

      <legend class="uk-legend">Add Teachers</legend>

      <div class="uk-margin">
        <input class="uk-input" type="text" name="name" placeholder="Name">
      </div>
      <div class="uk-margin">
        <div class="uk-form-controls">
          <select class="uk-select" id="form-horizontal-select" name="subject01">
            <option value="0" selected="selected" disabled=disabled>Select Subject 01</option>
            <option value="math">Mathematics</option>
            <option value="sci">Science</option>
            <option value="eng">English</option>
            <option value="hin">Hindi</option>
            <option value="kan">Kannada</option>
            <option value="ss">Social Science</option>
            <option value="pe">Physical Education</option>
            <option value="moralSci">Moral Science</option>
            <option value="draw">Drawing</option>
            <option value="music">Music</option>
          </select>
        </div>
      </div>
      <div class="uk-margin">
        <div class="uk-form-controls">
          <select class="uk-select" id="form-horizontal-select2" name="subject02">
            <option value="0" selected="selected" disabled=disabled>Select Subject 02</option>
            <option value="math">Mathematics</option>
            <option value="sci">Science</option>
            <option value="eng">English</option>
            <option value="hin">Hindi</option>
            <option value="kan">Kannada</option>
            <option value="ss">Social Science</option>
            <option value="pe">Physical Education</option>
            <option value="moralSci">Moral Science</option>
            <option value="draw">Drawing</option>
            <option value="music">Music</option>
          </select>
        </div>
      </div>
      <div class="uk-margin">
        <div class="uk-form-controls">
          <select class="uk-select" id="form-horizontal-select3" name="subject03">
            <option value="0" selected="selected" disabled=disabled>Select Subject 03</option>
            <option value="math">Mathematics</option>
            <option value="sci">Science</option>
            <option value="eng">English</option>
            <option value="hin">Hindi</option>
            <option value="kan">Kannada</option>
            <option value="ss">Social Science</option>
            <option value="pe">Physical Education</option>
            <option value="moralSci">Moral Science</option>
            <option value="draw">Drawing</option>
            <option value="music">Music</option>
          </select>
        </div>
      </div>
      <div class="uk-margin">
        <div class="uk-form-controls">
          <select class="uk-select" id="form-horizontal-select4" name="subject04">
            <option value="0" selected="selected" disabled=disabled>Select Subject 04</option>
            <option value="math">Mathematics</option>
            <option value="sci">Science</option>
            <option value="eng">English</option>
            <option value="hin">Hindi</option>
            <option value="kan">Kannada</option>
            <option value="ss">Social Science</option>
            <option value="pe">Physical Education</option>
            <option value="moralSci">Moral Science</option>
            <option value="draw">Drawing</option>
            <option value="music">Music</option>
          </select>
        </div>
      </div>
      <div class="uk-margin">
        <input class="uk-button uk-button-default submit" type="submit" name="submit1" value="Add Teacher">
      </div>
    </fieldset>
  </form>

  <?php
                    if (isset($_POST["submit1"]) ) {
                        mysqli_query($link, "INSERT INTO `teachers`(`idTeacher`, `name`, `sub01`, `sub02`, `sub03`, `sub04`) VALUES ('','$_POST[name]','$_POST[subject01]','$_POST[subject02]','$_POST[subject03]','$_POST[subject04]')");
                        
                            ?>
    <div class="uk-text-center w3-padding w3-green w3-round-large"><strong>Added Successfully</strong></div>
    <?php
                        }
                        
                ?>
</div>
</div>
<?php include "htmlEnd.php";?>

我已经提到了类似的问题,但无法消除错误/警告。
Ref1 Ref2

我尝试使用反引号(`)代替答案之一的注释中建议的'。
数据确实已添加到数据库表中,但是此警告不断弹出。

0 个答案:

没有答案