php - 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'] . '" >';
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
Answer
Solution:
You assign same id. It's rule violation. Instead of
id
useclass
anddata-id
.And to catch data-id use button class with
this
:Answer
Solution:
Quick note: Avoid SQL Injections by preparing your SQL Queries :
PDO : https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection
Mysqli : https://websitebeaver.com/prepared-statements-in-php-mysqli-to-prevent-sql-injection