steviez Posted February 8, 2007 Share Posted February 8, 2007 Hi, On my site i want to give the users the option to close their account, what sort of code do i need to delete them from the database when they click delete. Any help would be great! Thanks Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/ Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 Get your delete button to post the users username, then simpl run a query something like... DELETE FROM users WHERE username = '$username'; Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/#findComment-179953 Share on other sites More sharing options...
steviez Posted February 8, 2007 Author Share Posted February 8, 2007 im a complete nubeeeeeeeee so ill need more help im affraid. Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/#findComment-179959 Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 Do you want me to write it for you? Thats not what this site is about. How about you make an attemtp, and post your code if your having problems? Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/#findComment-179963 Share on other sites More sharing options...
steviez Posted February 8, 2007 Author Share Posted February 8, 2007 This is my code so far and it dont work, any ideas? <?php include("connect.php"); include("header.php"); if(($user_id != "") && ($remove_user != "")) { $update_user = "DELETE FROM users WHERE id = '$UsErId'"; $update_result = mysql_query($update_user); $redirect = $SITEURL."logout.php"; header("location:$redirect"); } ?> <style type="text/css"> <!-- body { background-image: url("../images/body_background.gif"); } --> </style> <table align="center" width="780" class="frame"> <tr> <td><table width="100%" class="page_content_frame"> <tr> <td><p>By clicking delete account you understand that this can not be reversedand all your work will be lost</p> <p><form name="user" action="#" method="get"> <input type="hidden" value="<?php echo $row_top[user_id] ?>" name="user_id"> <input type="submit" name="remove_user" value="Delete My Account" class="button"> </form></p></td> </tr> </table></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/#findComment-179987 Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 Actually.... if your users have acoiunts then I'll assume they log in via sessions. Its safer to use this session data to delete the user. Simply make your delete link point to this script. <?php session_start(); if (isset($_SESSION['userid'])) { $sql = "DELETE FROM users WHERE userid = '{$_SESSION['userid']}'"; if (mysql_query($sql)) { $redirect = $SITEURL."logout.php"; header("location:$redirect"); } else { echo "Delete failed"; } } ?> Of course you'll need to change $_SESSION['userid'] to suite your application, but this should give you the idea. Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/#findComment-179989 Share on other sites More sharing options...
steviez Posted February 8, 2007 Author Share Posted February 8, 2007 I have tryed everything, how do i make a link to delete? Link to comment https://forums.phpfreaks.com/topic/37622-coding-help/#findComment-179992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.