Jump to content

Help editing a sign up script to remove a user


abreck

Recommended Posts

That script just takes data from a user, checks for validity and adds the user if it is OK.

 

What you want to do is similar - ask for a user's name, check if it exists (validate) and delete it if its there. I'd say yes, it can be easily modified although you'd probably want to verify with the user that they really want to delete it.

Basically you need to create a new script. The add script does something completely different than what your wanting to do.

 

There are 2 parts to your script, the first is to query the db and display a list of users.

 

The second is to click a link and have the script to delete the user.

 

Try this and lemme know what you get.....

 

It uses the unique id of the users table. I have it as userId, but that may not be right.... so change it to whatever the actual numeric id field is...

 

Name the page whatever you want, and it is not protected in any way, so be careful with it. :)

 

**Warning... it will delete users if I did not make any typos... I won't be responsible if you accidentally delete users that were not meant to be deleted**

 

<?php
require('main.php');
db_connect();
include(INC_DIR."header.php");


if(isset($_GET['action']) && $_GET['action'] == 'delete')
{
$userId = mysql_real_escape_string($_GET['uid'];
$sql = "DELETE FROM users WHERE userId = '$userId'";
$result = mysql_query($sql);
if(mysql_affected_rows() > 0)
{
	echo 'User Deleted';
}	
}

$sql = "SELECT * FROM users";
$result = mysql_query($sql);
?>
<table width="200" border="0">
  <tr>
    <td>Delete?</td>
    <td>Username</td>
  </tr>
<?php
	while($row = mysql_fetch_object($result))
{
	/*
		  Change userId to whatever the field name for the actual ID field in the db is
	*/
	echo '<tr>
			<td><a href="'.$_SERVER['PHP_SELF'].'?action=delete&userId='.$row->userId.'" onClick="return confirm(\' Are you sure you want to delete this user??\')">Delete</a></td>
			<td>'.$row->uid.'</td>
	  	</tr>';
}
?>
</table>

<?php
    include(INC_DIR."footer.php");
    db_disconnect();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.