Forgot Password / Register
Site Statistics
Total Members: 509
Total Tutorials: 242
Newsest User: Lestop
Todays Unique Hits: 97
0 Users 1 Guests Online

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.
SkillMaster
Views:
1345
Rating:
Posted on Tuesday 8th April 2008 at 05:24 PM
Dalez
Dalez
Thanks, this is very useful!
Posted on Thursday 28th June 2007 at 08:39 PM
SkillMaster
SkillMaster
0.o Dan giving me kudos. ~Feels all happy inside~

Thanks Dan(Y)
Posted on Thursday 28th June 2007 at 08:37 PM
DanielXP
DanielXP
Nice tutorial. Also like the confirmation that you want to delete the user.