title: Insert Values from a form to an array, then into a database
body: <p>I would like to get user values from an HTML form to an array and then insert it into a mysql database. it insert correct values into the database, then it gives out the following error:</p>
  
  <blockquote>
    <p>Notice: Undefined index: TopicNum in C:\wamp\www\Capturing System\All_Topics_widget.php on line 153</p>
  </blockquote>
  
  <p>The following is right at the top of the page:</p>
  
  <pre><code>&lt;?php 
  include 'scripts/functions/init.php';
  Restrict();
  </code></pre>
  
  <p>?>
  
  
  <pre><code>$userid = $_SESSION['userid'];
  $KM_Number = $_SESSION['C_KM'];
  $query = "SELECT * FROM knowledge_modules where km_number = "."'".$KM_Number."'";
  $Knowledge = mysql_query($query) or die(mysql_error);
  $row = mysql_fetch_assoc($Knowledge);
  $Module_type = 'Knowledge Modules';
  $Purpose_M = $_SESSION['Purpose_KM'];
  $KM = 'KM';
  $NUM = $_SESSION['KM'];
  $KT = 'KT';
  
  if (empty($_POST)=== false)
      {
          $R_fields = array('Topic_Num','Title','Weight');
          foreach($_POST as $key=&gt;$value)
          {
              if (empty($value) &amp;&amp; in_array($key,$R_fields)=== true)
                  {
                      $errors[] = 'fields marked with (*) are required';
                      break 1;
                  }
          }
  
          if(empty($errors)=== true)
              {
                  if(topic_exists($_POST['TopicNum']))
                      {
                          $errors[] = 'Sorry, the Topic already exist!';
                      }
  
  
              }
      }
  </code></pre>
  
  <p>?>
  The following code is within the HTML Tags:</p>
  
  <pre><code>&lt;h2&gt;Tools - &lt;/h2&gt;
  
              &lt;form action="All_Topics_widget.php" method="POST" enctype="multipart/form-data"&gt;
                &lt;fieldset&gt;
                  &lt;table border="0"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;label for="TopicNum"&gt;Topic Number:*&amp;nbsp&lt;?php echo $KM.'-'.$NUM.'-'.$KT ?&gt;&lt;/label&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;input type="text" size="5" name="TopicNum" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;label for="Title"&gt;Title:*&lt;/label&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;input type="Text" size="35" name="Title"/&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;label for="Weight"&gt;Weight:*&lt;/label&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;input type="text" size="05" name="Weight" /&gt;&lt;/td&gt;
  
                      &lt;/tr&gt;
  
                  &lt;/table&gt;
              &lt;/fieldset&gt;
                &lt;fieldset&gt;
                         &lt;table border="0"&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;&lt;input id="Submit" type="submit" value="Capture" /&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;input id="Reset1" type="reset" value="reset" /&gt;&lt;/td&gt;
                                   &lt;td&gt;&lt;a href="list_topics.php"&gt;Capture Topics&lt;/a&gt;&lt;/td&gt;
  
                             &lt;/tr&gt;
                          &lt;/table&gt;
                &lt;/fieldset&gt;
                &lt;?php
  
                      $Topics = $KM.'-'.$NUM.'-'.$KT.$_POST['TopicNum'];//This is line 153
                      if(isset($_GET['success']) &amp;&amp; empty($_GET['success']))
                          {
                              echo 'Succefully Captured';
                          }
                      else
                          {
                              if(empty($_POST) == false &amp;&amp; empty($errors)== true)
                                  {
  
                                      //Capture data from the fields to an array
                                      $capture_topic = array(
                                      'TopicNum' =&gt; $Topics,
                                      'Title'=&gt;$_POST['Title'],
                                      'Weight'=&gt;$_POST['Weight'],
                                      'Purpose_M'=&gt;$Purpose_M,
                                      'userid'=&gt;$userid);                                     
  
                                      //Submit the data into the database
                                      capture_topic($capture_topic);
                                      //redirect to the Modules widget page till the user press NEXT Page
                                      header('Location: All_Topics_widget.php?success');
                                      exit();
  
                                  }
  
                              else if(empty($errors)== false)
                                  {
                                      //Display errors
  
                                      echo output($errors);
                                  }
                          }
  
                ?&gt;
         &lt;/form&gt;
  </code></pre>