xmaster
xmaster

Reputation: 1050

Can't edit the second user

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'] . '" class="changeUser">';

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

            if ($row['active'] == 0 || $row['active'] == 2) {
                echo '      <button class="button button-green" onclick="approveOne('.$row['user_id'].', '.$_SESSION['org_id'].')">Approve</button>';
            }
            echo '      <button class="button button-red" 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

Upvotes: 0

Views: 76

Answers (2)

4b0
4b0

Reputation: 22323

You assign same id. It's rule violation. Instead of id use class and data-id .

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

And to catch data-id use button class with this:

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

Upvotes: 2

Related Questions