title: Trying to take EmployeeID & EName from dropdown to be used in a query to display table
body: <p>I have a training matrix/Tracking website I am working on. I have the drop-down populated from the database from a different table. I was able to display table data from another two tables referencing the user id displaying the name of the user at the top and then a table with all training completed underneath.</p>
  
  <p>I have got the dropdown working but I am struggling to get the database to pull data into a table using the id set in the dropdown box.</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  // We need to use sessions, so you should always start sessions using the below code.
  session_start();
  // If the user is not logged in redirect to the login page...
  if (!isset($_SESSION['loggedin'])) {
      header('Location: index.html');
      exit();
  }
  ?&gt;
  
  &lt;?php
  include ("templates/header.php");
  include ("connect-db.php");
  ?&gt;
  &lt;?php
  $EmployeeID = $_POST['Get'];
      $sqlEmployee = "SELECT EmployeeID, EName FROM employee ORDER BY EName";
      $stmtEmployee = $dbCon-&gt;prepare($sqlEmployee);
      $arrEmployee = array();
      $stmtEmployee-&gt;bindValue(':EmployeeID', $EmployeeID); 
          if ($stmtEmployee-&gt;execute()) {
                  $arrEmployee = $stmtEmployee-&gt;fetchAll(PDO::FETCH_ASSOC);
  }
  
  if (!isset($_POST['EmployeeID'])) {
  
      $sql = "SELECT * FROM employee";
      $stmtTable = $dbCon-&gt;prepare($sql);
      $stmtTable-&gt;execute();
  }
  ?&gt;
  &lt;center&gt;
  &lt;form action="search.php" method="post"&gt;
  
  &lt;label for="EmployeeID"&gt;Employee&lt;/label&gt;
      &lt;select name="EmployeeID" id="EmployeeID"&gt;
      &lt;?php
        for($i=0;$i&lt;count($arrEmployee);$i++) {
           $row = $arrEmployee[$i];
        ?&gt;
        &lt;option value="&lt;?= $row['EmployeeID'] ?&gt;" &lt;?php echo "Selected='selected'"?&gt; &gt;&lt;?= $row['EName'] ?&gt;&lt;/option&gt;
        &lt;?php
        }
      ?&gt;
      &lt;/select&gt;
      &lt;input type="submit" name="Get" value="Add New Record"&gt;&lt;/button&gt;
  &lt;/center&gt;
  
  &lt;?php
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;Name&lt;/th&gt;
  &lt;th&gt;Home&lt;/th&gt;
  &lt;th&gt;Shift&lt;/th&gt;
  &lt;th&gt;Start Date&lt;/th&gt;
  
  
  &lt;/tr&gt;";
  
  while ($rowTable = $stmtTable-&gt;fetch($sql)) 
  {
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;" . $rowTable['EName'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $rowTable['HomeBase'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $rowTable['Shift'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $rowTable['StartDate'] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;";
  $stmtTable=Null
  
  ?&gt;
  
  &lt;?php
  include ("templates/footer.php");
  ?&gt;
  </code></pre>
  
  <p>I am getting an error where it doesn't get the variable. I know how to join databases but struggling to get a simple name shift startdate data.</p>
  
  <p>New Code After Updates</p>
  
  <pre><code>&lt;?php
  
      error_reporting(E_ALL);
      ini_set('display_errors', 1);
  
      // We need to use sessions, so you should always start sessions using the below code.
      session_start();
  
      // If the user is not logged in redirect to the login page...
      if (!isset($_SESSION['loggedin'])) {
          header('Location: index.html');
          exit();
      }
      //includes for page
      include ("templates/header.php");
      include ("connect-db.php");
      // This one below is for the dropdown box to populate the user name
  
      $EmployeeID = $_POST['EmployeeID']; //changed this to EMployeeID from Get
      $sqlEmployee = "SELECT EmployeeID, EName FROM employee ORDER BY EName";
      $stmtEmployee = $dbCon-&gt;prepare($sqlEmployee);
      $stmtEmployee-&gt;bindValue(':EmployeeID', $EmployeeID);
  
      $arrEmployee = array();
  
      if ($stmtEmployee-&gt;execute()) {
          $arrEmployee = $stmtEmployee-&gt;fetchAll(PDO::FETCH_ASSOC);
      }
  
  ?&gt;
  &lt;center&gt;
      &lt;form action="search.php" method="post"&gt;
          &lt;label for="EmployeeID"&gt;Employee&lt;/label&gt;
          &lt;select name="EmployeeID" id="EmployeeID"&gt;
  &lt;?php
          //this is a dropdown box for the top of the page to be able to select user to display data on
  
              for($i=0;$i&lt;count($arrEmployee);$i++) {
                  $row = $arrEmployee[$i];
                  echo '&lt;option value="' . $row['EmployeeID'] . '"&gt;' . $row['EName'] . '&lt;/option&gt;';
              }
  
          ?&gt;
          &lt;/select&gt;
          &lt;button type="submit" name="Get"&gt;Get&lt;/button&gt;
      &lt;/form&gt;
  &lt;/center&gt;
  
  &lt;table border='1'&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Home&lt;/th&gt;
              &lt;th&gt;Shift&lt;/th&gt;
              &lt;th&gt;Start Date&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
     &lt;?php
          //this is for the data in the table to be populated using the dropdown as the source for the id to display the user data ect.
      if (!isset($_POST['EmployeeID'])) {
          $sql = "SELECT * FROM employee Where EmployeeID = $EmployeeID";
          $stmtTable = $dbCon-&gt;prepare($sql);
          $stmtTable-&gt;execute();
  
          while ($rowTable = $stmtTable-&gt;fetch()) {
              echo "&lt;tr&gt;";
              echo "&lt;td&gt;" . $rowTable['EName'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $rowTable['HomeBase'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $rowTable['Shift'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $rowTable['StartDate'] . "&lt;/td&gt;";
              echo "&lt;/tr&gt;";
          }
      } else {
          echo '&lt;tr&gt;&lt;td colspan="4"&gt;No records found&lt;/td&gt;';
      }
  
      ?&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;?php include ("templates/footer.php"); ?&gt;
  </code></pre>
  
  <p><strong>Update 2</strong>
  By Changing the if (!isset($_POST['EmployeeID'])) to if (isset($_POST['EmployeeID'])) this made the page work but i still get the error "Notice: Undefined index: EmployeeID in C:\UniServerZ\www\search.php on line 19" when first loading the page but after clicking a name this goes away.</p>