abreck Posted November 8, 2008 Share Posted November 8, 2008 I have a script for adding users to a sql database. Though there was no accompanying script for removing a user. Could the script That I am linking to be easily modified to remove the user? http://www.fayshalecitizens.org/signup.txt Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/ Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 I'm getting redirected to a Google-style appearance of "OpenDNS Guide"... Can you post the code here? Remove any passwords etc. first if any are present. Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685553 Share on other sites More sharing options...
abreck Posted November 8, 2008 Author Share Posted November 8, 2008 corrected.. sorry Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685554 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685559 Share on other sites More sharing options...
abreck Posted November 8, 2008 Author Share Posted November 8, 2008 In the end this script will only be accessible if authenticated as myself or the site owner. Users will not be able to add themselves nor delete themselves. Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685567 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 Still a good idea to verify first, what happens if you accidentally choose the wrong user? Easily done! Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685579 Share on other sites More sharing options...
abreck Posted November 8, 2008 Author Share Posted November 8, 2008 very true.. I will have to a confirmation line. I am completely new to pHp. So i would have to figure that out as well. What would I have to change in that file so that it remove as opposed to add? Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685580 Share on other sites More sharing options...
chronister Posted November 8, 2008 Share Posted November 8, 2008 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(); ?> Link to comment https://forums.phpfreaks.com/topic/131947-help-editing-a-sign-up-script-to-remove-a-user/#findComment-685619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.