title: Why this gives me a notice and warning when i add multiple choice answer what should i do?
body: <p>array(4) { ["txt"]=> array(4) { [0]=> string(11) "action word" [1]=> string(6) "nothing" [2]=> string(5) "just a word" [3]=> string(9) "i dont know" } ["radioans"]=> string(5) "txta1" ["btnadd"]=> string(0) "" ["h1"]=> string(2) "38" }</p>
  
  <p><strong>Notice: Undefined index: txt[] in C:\xampp\htdocs\quiEZ\adminanswer.php on line 10</strong></p>
  
  <blockquote>
  <pre><code>$answers=htmlspecialchars($_POST["txt[]"]);
  </code></pre>
  </blockquote>
  
  <p><strong>Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\quiEZ\adminans.php on line 15</strong></p>
  
  <blockquote>
  <pre><code>foreach($answers as $key=&gt;$ans){
  </code></pre>
  </blockquote>
  
  <pre><code>&lt;?php
  $title = "QuiEZ - Add Answers";
  include_once "includes/db.php";
  include_once "includes/header.php";
  if (!isset($_SESSION["userid"], $_SESSION["sid"], $_SESSION["userrole"]) || $_SESSION["userrole"] != "A") {
      header("Location:login.php");
  }
  if (isset($_POST["btnadd"])) {
      var_dump($_POST);
      $answers=htmlspecialchars($_POST["txt[]"]);
      $rightans=(int) preg_replace('/[^0-9]/', '', filter_input(INPUT_POST,"radioans"));
      $aqid=filter_input(INPUT_POST,"h1");
      $db = new db;
      $link = $db-&gt;dbconnect();
      foreach($answers as $key=&gt;$ans){
          if($key+1==$rightans){
              $qry="insert tbans values(null,$aqid,'$ans','T','".date('Y/m/d')."')";
          }else{
              $qry="insert tbans values(null,$aqid,'$ans','F','".date('Y/m/d')."')";
          }
          mysqli_query($link,$qry);
          header("Location:admques.php");
      }
  }
  
  ?&gt;
  
      &lt;div class="uk-card uk-card-default uk-card-hover uk-card-body uk-width-1-2@m uk-width-1-2@s uk-align-center uk-margin-auto@s uk-margin-remove-bottom"&gt;
      &lt;?php
      if (isset($_GET["qid"])) {
          ?&gt;
          &lt;form method="post" class="uk-width-auto" action="admans.php"&gt;
              &lt;legend class="uk-legend"&gt;Answers&lt;/legend&gt;
              &lt;div class="uk-width-1-1@s"&gt;
                  &lt;?php
                  $db = new db;
                  $link = $db-&gt;dbconnect();
                  $qry = "select * from tbque where qid=" . filter_input(INPUT_GET, "qid");
                  $res = mysqli_query($link, $qry);
                  $r = mysqli_fetch_row($res);
                  echo "&lt;h2&gt;$r[1]&lt;/h2&gt;";
                  mysqli_free_result($res);
                  ?&gt;
              &lt;/div&gt;
              &lt;div class="uk-margin"&gt;
                  &lt;input class="uk-input" name="txt[]"
                         type="text"
                         placeholder="Answer 1.." required&gt;
                  RIGHT ANSWER OR NOT? &lt;input class="uk-radio" value="txta1" name="radioans" type="radio"&gt;
              &lt;/div&gt;
              &lt;div class="uk-margin"&gt;
                  &lt;input class="uk-input" name="txt[]"
                         placeholder="Answer 2.." required&gt;
                  RIGHT ANSWER OR NOT? &lt;input class="uk-radio" value="txta2" name="radioans" type="radio"&gt;
  
              &lt;/div&gt;
              &lt;div class="uk-margin"&gt;
                  &lt;input class="uk-input" name="txt[]"
                         placeholder="Answer 3.." required&gt;
                  RIGHT ANSWER OR NOT? &lt;input class="uk-radio" value="txta3" name="radioans" type="radio"&gt;
  
              &lt;/div&gt;
              &lt;div class="uk-margin"&gt;
                  &lt;input class="uk-input" name="txt[]"
                         placeholder="Answer 4.." required&gt;
                  RIGHT ANSWER OR NOT? &lt;input class="uk-radio" value="txta4" name="radioans" type="radio"&gt;
              &lt;/div&gt;
              &lt;div class="uk-align-center uk-text-center"&gt;
                  &lt;button type="submit" name="btnadd" class="uk-button-large uk-button-primary"&gt;ADD&lt;/button&gt;
                  &lt;input type="hidden" name="h1" value="&lt;?=filter_input(INPUT_GET,"qid")?&gt;"/&gt;
              &lt;/div&gt;
          &lt;/form&gt;
          &lt;?php
          $qid = filter_input(INPUT_GET, "qid");
          $qry = "SELECT atxt FROM `tbans` where aqid=$qid";
          $res = mysqli_query($link, $qry);
          if (mysqli_num_rows($res)) {
              ?&gt;
              &lt;table class="uk-table uk-table-divider uk-table-responsive uk-width-auto"&gt;
                  &lt;caption&gt;Answers&lt;/caption&gt;
                  &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;?php
                      $i = 1;
                      while ($r = mysqli_fetch_row($res)) {
                          ?&gt;
                          &lt;td&gt;&lt;strong&gt;&lt;?= $i ?&gt;. &lt;span class="uk-text-bolder"&gt;&lt;?= $r[0] ?&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;
                          &lt;?php
                          $i++;
                      }
                      mysqli_free_result($res);
                      ?&gt;
                  &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;?php
          }
      } else {
          if (isset($msg)) {
              echo $msg;
          } else {
              echo "NOTHING HERE!";
          }
      }
      ?&gt;
  &lt;/div&gt;
  </code></pre>