php - Can't edit the second user

878

I have a page where you can edit a user. If you click the edit button you get redirected to a page where you can edit that user. It works perfectly for the first person but when I click the edit button of the second user it does nothing. No errors nothing. You are not getting redirected to the page.

My PHP

function getUsers($orgID, $type)
{
  require 'functions/conn.php';
  $sql = "SELECT users.*, parts.*, keuze.* FROM ((users INNER JOIN parts ON users.part_id = parts.part_id) INNER JOIN keuze ON users.keuze_ID = keuze.ID) WHERE users.org_id = '" . $orgID . "' AND users.active = '" . $type . "';";
  $result = $conn->query($sql);
  if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
      echo '<tr id="' . $row['user_id'] . '" >';

      echo ' <td>' . $row['fnln'] . '</td>';
      echo ' <td>' . $row['username'] . '</td>';
      echo ' <td>' . $row['name'] . '</td>';
      echo ' <td>' . $row['keuze'] . '</td>';
      echo ' <td>';
        echo '   <button id="btnChangeUser">Eind tijd</button>';

      if ($row['active'] == 0 || $row['active'] == 2) {
        echo '   <button onclick="approveOne('.$row['user_id'].', '.$_SESSION['org_id'].')">Approve</button>';
      }
      echo '   <button onclick="deleteFromRelation(' . $row['user_id'] . ');">Delete</button><br/>';
      echo ' </td>';
      echo '</tr>';
    }
  }
}

My Jquery

<script>

$("#btnChangeUser").click(function () {
    var userID = $(".changeUser").attr('id');
    window.location.href = "changeuser?user=" + userID + "";
});

function changeItem(userID) {
    window.location.href = "changeuser?user=" + userID + "";
}

</script>

What I expect is that if I click on the edit button of the second user it will redirect me.

Edit

the second row is the row I can't edit. enter image description here

37

Answer

Solution:

You assign same id. It's rule violation. Instead ofid useclass anddata-id .

<button class="button button-orange" data-id="' . $row['user_id'] . '">Eind tijd</button>';

And to catch data-id use button class withthis:

$(".button-orange").click(function () {
    var userID = $(this).data('id');
    window.location.href = "changeuser?user=" + userID + "";
});

People are also looking for solutions to the problem: php - Two templates showed

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.