title: Trying to create a $_POST function using a form, and having trouble passing the right values due to form's not being allowed inside table's
body: <p>I have a form that sends information from a user database to a $_POST function. I got the information to pass the values to the function, but it's only sending the last entry from the database column. For example I'm trying to update the database row with an ID of '1', but instead it keeps updating the row with an ID '9'. Inside the form there is a table which displays all the user information using a foreach loop, and using inputs, the information is passed when a button is pressed. All the other information passes fine, just not the ID.</p>
  
  <p>I think it caused by the form being outside the foreach loop, making It only send the last value it receives. The code will be posted below and I'm mainly wondering if anyone knows of any workarounds for using forms and tables together? or is it just a case of using lots of css.</p>
  
  <p><strong>The foreach loop inside the form uses a variable which gets its info from a sql function:</strong> </p>
  
  <pre><code>//calls the function at the top of the page
  
  $userData = getUserProf();
  
  ///////////////////////////
  
  // function to return all the data from the user database
  function getUserProf() {
      global $conn;
  
      // select data from user database
      $sql = "SELECT * FROM users";
      $userData = mysqli_query($conn, $sql);
  
      $getUserData = mysqli_fetch_all($userData, MYSQLI_ASSOC);
  
      // return user data
      return $getUserData;
  }
  
  ///////////////////////////
  </code></pre>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;form action="includes/adminActions.scr.php" method="POST"&gt;
      &lt;table class="ui padded celled table"&gt;
          &lt;thead&gt;
          &lt;tr&gt;&lt;th&gt;UserID&lt;/th&gt;
              &lt;th&gt;Username&lt;/th&gt;
              &lt;th&gt;Email&lt;/th&gt;
              &lt;th&gt;Password&lt;/th&gt;
              &lt;th&gt;User Role&lt;/th&gt;
              &lt;th&gt;Actions&lt;/th&gt;
          &lt;/tr&gt;&lt;/thead&gt;
          &lt;tbody&gt;
          &lt;?php foreach ($userData as $user): ?&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;div class="ui fluid disabled transparent input"&gt;&lt;input name="userId" placeholder="&lt;?php echo htmlentities($user['userID']) ?&gt;" value="&lt;?php echo $user['userID']?&gt;"/&gt;&lt;/div&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;div class="ui input"&gt;&lt;input name="username" placeholder="&lt;?php echo htmlentities($user['username']) ?&gt;"/&gt;&lt;/div&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;div class="ui input"&gt;&lt;input name="email" placeholder="&lt;?php echo htmlentities($user['email']) ?&gt;"/&gt;&lt;/div&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;div class="ui input"&gt;&lt;input name="password" placeholder="&lt;?php echo htmlentities($user['password']) ?&gt;"/&gt;&lt;/div&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;h3&gt;&lt;?php echo htmlentities($user['user_lvl']) ?&gt;&lt;/h3&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;button type="submit" class="ui small blue button" name="updateUser"&gt;Update&lt;/button&gt;
                      &lt;a href="includes/adminActions.scr.php?makeAdmin=&lt;?php echo $user['userID']?&gt;" class="ui small green button"&gt;Lvl Up&lt;/a&gt;
                      &lt;a href="includes/adminActions.scr.php?deleteUser=&lt;?php echo $user['userID']?&gt;" class="ui small red button"&gt;Delete&lt;/a&gt;
                      &lt;a href="includes/adminActions.scr.php?makeUser=&lt;?php echo $user['userID']?&gt;" class="ui small orange button"&gt;Lvl Down&lt;/a&gt;
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;?php endforeach; ?&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>And then finally, here is the two parts from the actions script:</strong></p>
  
  <pre><code>// if user clicks the update button
  if (isset($_POST['updateUser'])) {
      updateUser($_POST);
  }
  
  // take in POST variables and update the database
  function updateUser($postValues) {
      global $conn, $userID, $username, $email, $password;
      $userID = ($postValues['userId']);
      $username = ($postValues['username']);
      $email = ($postValues['email']);
      $password = ($postValues['password']);
  
      $hashedPass = password_hash($password, PASSWORD_DEFAULT);
  
      $sql = "UPDATE users SET username = '$username', email = '$email', password = '$hashedPass' WHERE userID = '$userID'";
  
      if (mysqli_query($conn, $sql)) {
          header("location: ../editUsers.php?isEditing=1&amp;userID=$userID");
          exit();
      } else {
          header("Location: ../editUsers.php?mysqlerror");
          exit();
      }
  }
  </code></pre>