Delete members

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Delete members

Post by ericburnard »

hi there. i now have my members area set up on my site but am wanting to make am easy admin page where i can delete members without having to go into the database to delete them. I have the following script (mainly from php.net) to display all of the users in the table.

How can i modifly it to beable to delete members???

Thanks
Eric#

Code: Select all

<?
include('http://eric.madashatters.com/header.inc')
?>

<?php
$link = mysql_connect('localhost', 'madashat_eric', '********')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('madashat_users') or die('Could not select database');

$query = 'SELECT * FROM users';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

echo "<table>\n<div class='white'>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td><div class='white'>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

mysql_free_result($result);

mysql_close($link);
?>

<?
include('http://eric.madashatters.com/footer.inc')
?>
include('http://eric.madashatters.com/header.inc')
?&gt;

&lt;?php
$link = mysql_connect('localhost', 'madashat_eric', '********')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('madashat_users') or die('Could not select database');

$query = 'SELECT * FROM users';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

echo &quote;&lt;table&gt;\n&lt;div class='white'&gt;&quote;;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo &quote;\t&lt;tr&gt;\n&quote;;
foreach ($line as $col_value) {
echo &quote;\t\t&lt;td&gt;&lt;div class='white'&gt;$col_value&lt;/td&gt;\n&quote;;
}
echo &quote;\t&lt;/tr&gt;\n&quote;;
}
echo &quote;&lt;/table&gt;\n&quote;;

mysql_free_result($result);

mysql_close($link);
?&gt;

&lt;?
include('http://eric.madashatters.com/footer.inc')
?&gt;
mp;quote;;

mysql_free_result($result);

mysql_close($link);
?>

<?
include('http://eric.madashatters.com/footer.inc')
?>
Last edited by ericburnard on Sun Jul 10, 2005 9:47 am, edited 1 time in total.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Warning: Eric please get rid of the password bit on your code.
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

Dale wrote:Warning: Eric please get rid of the password bit on your code.
Tis changed. Can you offer me some help??

Eric
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Suggestion:Instead of completely removing the member from your system, rather disable the member. Have a field called "record_status_id" or something like that. Have 1 as active and 2 as disabled (example).

When you show your members, have a hyperlink next to the member that sends the members id in the database to your edit page. The benefit of this is, if your member returns, you don't have to capture all their detail again.

Then on your edit page, specify the record status in a select (drop down). Then you can merely activate or disable the member.
Abs
Forum Newbie
Posts: 7
Joined: Sat Jul 09, 2005 11:59 am
Location: Toronto, Canada

Post by Abs »

If you REALLY need to delete them though (NOTE: The suggestion above mine is a WAY better way of doing it), type:

Code: Select all

$query = &quote;delete from users where userid = $userid&quote;;

[EDIT: P.s.: I hope my syntax is correct...if it isn't, just Google 'mysql and delete']
Post Reply