I have a few tables that list different things: questions, replies, and users. The tables are from an admin's pov. On the left side, the code makes a cell that contains a small cancel.png img that's supposed to be a delete button for the row. Right now, it's not doing anything when I click on any of the buttons (there's many) yet the hover cursor animation is triggered when I hover over them. I don't know what's wrong, I've had the JS checked by a different colleague of mine but he works for another facility.
I've tried editing the JS, checked the SQL queries in the PHP, checked the db whether or not it triggered anything there and it didn't. There weren't any good examples to take note from online either.
So here's where the code starts: this is the delete function.
<?php
if(isset($_GET['udel'])) {
$error = 0;
$uid = mysqli_real_escape_string($link, $_GET['udel']);
$query = "DELETE FROM users WHERE id = $uid;";
if (!mysqli_query($link, $query)) $error = 1;
if ($error == 0) $msg = 'The user has been deleted.';
else $msg = 'The user couldn\'t be deleted. Contact the website administrator if the problems persists.';
}
?>
There is php/html that calls another php file to print the (e.g. users) table:
<?php
printUsersTable(getUsers($link));
?>
It calls this stuff:
<?php // theres code above here
function printUsersTable($users) {
?>
<table class="neutral" border="0" style="width:500px;">
<thead>
<tr>
<th>DEL</th>
<th>Name</th>
<th>Email</th>
<th>Admin</th>
<th>State</th>
</tr>
</thead>
<tbody>
<?php foreach($users as $user) { ?>
<tr>
<td style="cursor: pointer";><img src="images/cancel.png" class="userDel" rel="<?=$user['id']?>" /></td>
<td><?=$user['name']?></td>
<td><?=$user['login']?></td>
<td><?php if($user['admin'] == 1) echo 'Y'; else echo 'N'; ?></td>
<td><?=$user['state']?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
}
// code continues
?>
Which is all printed (so it's included) onto that first admin page.
Then it goes to this (on the first admin page like the first part of the code), where the rel attribute should trigger if clicked on:
$(".userDel").click(function() {
var uid = $(this).attr("rel");
if(confirm("Are you sure you want to delete user " + uid + "?")) {
window.location = 'admin.php?udel=' + uid;
}
});
I've also tried this, but it doesn't work either:
$(".userDel").on('click', function(event) {
event.stopPropogation();
event.stopImmediatePropogation();
var uid = $(this).attr("rel");
if(confirm("Are you sure you want to delete user " + uid + "?")) {
window.location = 'admin.php?udel=' + uid;
}
});
On all my files, the php code comes first, then the JS, then any HTML. I'm out on my ass, can y'all help me out? (Also, I don't have any SQL injection vulns anywhere do I?) >.>