Hey Everyone, I found something Great!! I created the code myself, its allows your users to delete thier account if they dont want it anymore! It saves your sql data and its good for the user, it even has a warning page before they delete it! Heres the code Create a file called deleteaccount.php and put in the following code:
deleteaccount.php
delete.php
deleteaccount.php
- Code:
<?php
include("include/session.php");
if($session->logged_in){
echo"<h2> Delete Account</h2>
Hello $session->username!
<br><p> This is the delete account page. If you press continue you understand your username, password, ect. will be deleted from the database permanantly and you wont be able to login.<br>
You will be able to register again but all account data will be lost!</p><br><br><a href=delete.php>Continue</a> Or <a href=index.php>Back Out of it</a>";
}
else{
echo"<p> Your not logged in, go and <a href=register.php>Register</a>";
}
?>
delete.php
- Code:
<?php
include("include/session.php");
?>
<?php
$con = mysql_connect("localhost","username","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("your_db", $con);
mysql_query("DELETE FROM users WHERE username='$session->username'");
if (!mysql_query($sql,$con))
{
die('Go back to the <a href=index.php>Homepage</a> Because there was an error.<br> <small> Most likely if you are getting the message ,query was empty, then you are not logged in so the database had nothing to delete</small> <br> The Error was: '.mysql_error());
}
echo "Your username has been deleted, you have no name now so we just call you a guest. You may register again if you like! Also, if you submitted notes they have been submitted. Head back <a href=index.php>Head Home</a> ";
mysql_close($con);
?>
- Code:
<a href="deleteaccount.php">Delete My Account</a>