title: Accessing the ID from one table and inserting it into another table - PHP
body: <p>Currently I have a form which has dropdown list that contains values that have been accessed from the "Category" table, which has two fields, courseID and cName. This form is in a file called "add_item.php".</p>
  
  <pre><code>&lt;form action="../adminscripts/item_add.php" method="post" class="addItem"&gt;
      &lt;label&gt;2) Select Course&lt;/label&gt;
                          &lt;br&gt;
                      &lt;select class="dropdown" name="category"&gt;
                      &lt;?php 
                      include "..database/connect.php";
                      $query = mysqli_query($conn, "SELECT * FROM courses");
                      while ($row = mysqli_fetch_array($query)){
                      echo "&lt;option value='". $row['cName'] ."'&gt;" . $row['cName'] . " &lt;/option&gt;";
  
                      }
                          ?&gt;
  
   &lt;/select&gt;
   &lt;input class="send" type="submit" value="Add Menu Item" name="itemSubmit"&gt;
           &lt;/form&gt;
  </code></pre>
  
  <p>What I am trying to achieve is that when the user selects one of these values, and clicks the "itemSubmit" button, I want the courseID to be posted in the table "menu" along with all the other information on the form. At the moment everything is posted into the database other than the "courseID" which takes the value of "0" when posted in the database.</p>
  
  <p>The form action file "item_add.php" contains the code to submit the information:</p>
  
  <pre><code>&lt;?php
  session_start();
      require "../database/connect.php";
  
      if(isset($_POST['itemSubmit']))
      {
  $query2 = mysqli_query($conn, "INSERT INTO menu (mName, courseID, description, price) VALUES ('$itemname', '$courseID', '$item_description', '$price')" ) or die (mysqli_error($conn));
  
              header("Location:../admin/add_item.php");
  
  
              exit;
          }
  </code></pre>
  
  <p>I have tried to play around with global variables with no luck, hence me having "$courseID" in the above form.</p>
  
  <p>I have not included the file "item_add.php" in the "add_item.php" file because I only need it to fulfil the form action. I have been struggling to access the variable from one file and inserting it into another basically.</p>
  
  <p>Any help?</p>