Delete A Specific User.
I saw Dean's Delete Unactive Users but what if you wanted to delete a specific user?
So I thought what the hell I'll make a code, and here it is.
Okay no mysql queries so straight into the code.
Save as
delete_user.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
session_start();
include "config.php";
if($logged[username] && $logged[userlevel] == 6)
{
switch($_GET[page])
{
default:
$fetch = mysql_query("SELECT * FROM `members`");
while ($delete = mysql_fetch_array($fetch))
{
echo ("- <a href='?page=verifydelete&username=$delete[username]'>$delete[username]</a><br>");
}
break;
case 'verifydelete':
echo ("Are you sure you want to delete $_GET[username]?
<br><br>
<a href='?page=delete&username=$_GET[username]'>Yes</a> - <a href='delete_user.php'>No</a>");
break;
case 'delete':
$username = strip_tags(htmlspecialchars($_GET[username]));
$delete = mysql_query("DELETE FROM `members` WHERE username = '$username'");
echo ("User Deleted.<br><a href='delete_user.php'>Go back.</a>");
break;
}
}
else
{
echo ("You must be admin to view this page.");
}
?>
What do these codes mean? Take the time to read on and learn.
Code
<?php
session_start();
include "config.php";
if($logged[username] && $logged[userlevel] == 6)
{
Our all important header. Starts our session and makes sure that only the people with level 6 are allowed to view this page.
Code
$fetch = mysql_query("SELECT * FROM `members`");
while ($delete = mysql_fetch_array($fetch))
{
echo ("- <a href='?page=verifydelete&username=$delete[username]'>$delete[username]</a><br>");
}
It displays all of our members check out my tutorial in the Mysql category to see the explanation of the while tag.
Code
$username = strip_tags(htmlspecialchars($_GET[username]));
$delete = mysql_query("DELETE FROM `members` WHERE username = '$username'");
echo ("User Deleted.<br><a href='delete_user.php'>Go back.</a>");
Deletes our user from the database. And displays a message that our user is now deleted.
hope you liek this code.