Page 1 of 1

Delete members

Posted: Sun Jul 10, 2005 8:39 am
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')
?>

Posted: Sun Jul 10, 2005 9:13 am
by Dale
Warning: Eric please get rid of the password bit on your code.

Posted: Sun Jul 10, 2005 9:48 am
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

Posted: Sun Jul 10, 2005 2:28 pm
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.

Posted: Mon Jul 11, 2005 6:56 am
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']