I have a a problem when posting some info from a form to a delete function, I am probably going to kick my self for this but I can't find the answer.
- admin/index.php
- lib/admin_functions.php
- lib/delete_user.php
As above, I have 3 files.
The function it's self is below:
// Display users
function get_all_users() {
global $con;
$sql = "SELECT * FROM users ORDER BY id ASC";
$result = mysqli_query($con, $sql);
echo "<tr><td> </td><td> User ID </td><td> Username </td><td> Email Address </td><td> Zendesk User Id </td><td>
Zendesk View ID </td><td> Firstname </td><td> Surname </td><td> Nickname </td><td> Active
</td><td> Admin </td><td> Display Stats?</td><td> Remove User </td></tr>";
while($row = mysqli_fetch_array($result)) {
// Displaying all user details
echo "<tr><td><img height='40' width='40' src='{$row['user_photo']}'></td><td>" .$row['id']. "</td><td>" .$row['user_name']. "</td><td>" .$row['email_address']. "</td><td>" .$row['zendesk_user_id']."</td><td>"
.$row['zendesk_view_id']. "</td><td>" .$row['user_firstname']. "</td><td>" .$row['user_surname']. "</td><td>" .$row['user_nickname']. "</td><td>"
.$row['is_active']. "</td><td>" .$row['is_admin']. "</td><td>" .$row['display_stats'].
// Form for deleting a user
"</td><td><form id='delete_user' accept-charset='UTF-8' action='/delete_user.php' role='form' method='POST'><input type='checkbox' value='Delete'><input type='hidden' name='user_id' value='{$row['id']}'></td></tr>";
}
echo "<tr><td> Delete Selected User(s) </td><td>";
echo "<input type='submit' name='submit' value='Delete My Account' onClick=\"return confirm('Are you sure you want to delete this account?')\"></td></form></tr>";
}
The above function belongs in admin_functions.php, it displays all my users with an extra column with a tick box for deletion, and at the bottom a form with the delete button.
I then have the delete_user code
<?php
session_start();
if( ! $_SESSION['loggedIn'] && ! $_SESSION['isAdmin']) {
// If not admin or logged in, die
die();
}
require_once(dirname(__FILE__).'/admin_functions.php');
require_once(dirname(__FILE__).'/../config.php');
// DELETE USER
$user_id = mysql_real_escape_string( $_POST['user_id'] );
// Insert the customer, including the password hash
$sql = "DELETE FROM users where id = '{$user_id}' limit 1";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
print "User Deleted";
mysqli_close($con);
?>
And finally on the index file, I have something that calls the function.
<?php get_all_users(); ?>
The problem I have is that the code all displays as expected, but after the warning message nothing happens. Nothing appears to get posted to delete_user.php, I see no errors in apache2 and also nothing in my console.
Any ideas?