- This topic is empty.
-
AuthorPosts
-
December 9, 2010 at 8:16 pm #30956
Hadley17
MemberHello someone, or people.. lol
Heres my problem, i’m trying to delete a record from my sql database that displays a confirmation message with a continue button. If they press continue, their “account” is deleted and they will be redirected to the login page. Now, i have the code working that removes the account from the database, and redirects them to the login page.
Here is my code:
if(isset($_POST)){
$delete = $_GET;
$confirmDel = ‘
Are you sure you want to delete your account?
‘;
if(!isset($delete)){}
else
{
$query = “DELETE FROM users
WHERE username = ‘” . $username . “‘”;$rs = mysqli_query($oConn, $query);
session_unset();
session_destroy();
header(“location:registration.php”);
exit;
}
}Here is my problem:
As of where I stand at the moment, once i click the delete button, the confirmation message will be displayed along with the continue button. Although, all it does is refresh the page..it doesn’t delete and redirect.
Note: I’m a beginner at PHP and really not sure why this is happening and I dont know what to do. Your help would be greatly appreciated!
December 10, 2010 at 5:14 pm #70108TT_Mark
MemberI’m not entirely sure what you are doing here… As personal preference I would always have a JavaScript Confirm Delete box, but then also include a PHP delete to fall back on.
Your $confirmDel isn’t actually being output to the page at any point, unless you are missing some code? You also seem to be getting mixed up with $_POST and $_GET variables.
December 11, 2010 at 12:16 pm #70038Hadley17
Memberexactly, i’m a beginner and have no real idea what im doing. All i’m trying to do is to get a “are you sure you want to delete your account?” with a continue button to show up when they click delete. Then that message will show and if they click continue well, it will remove them from the database.
I have no idea how to do this in either javascript or php..
Some help and clarification would be amazing right now lol..
December 11, 2010 at 12:26 pm #70039rickylamerz
MemberDear Hadley17,
Im hoping your not planning to use this in a public environment?
Because if you aren’t able to do this you won’t be able to secure it. Anyway.I would suggest you doing the following ( along the lines of ):
$deleteRequest = $_POST('btnDelete'); //capture the status of the delete from a form that uses the "post" method to submit
if($deleteRequest == 'true'){
// if the #deleteRequest value is equal to 'true' then do the following
mysql_query(" DELETE FROM users WHERE username='$username' ");
}
?>
Something like this. It isn’t perfect but I think it’ll work. The difference between GET and POST is crucial to understand. I would suggest you walk through PHP tutorials @ w3schools.com worked wonders for me!
Greetings,
RickDecember 11, 2010 at 12:39 pm #70007Hadley17
Memberits not for a public environment, its an assignment for school and im completely lost, so i was searching for help..
I got whole delete from the database part good to go, although we need to have a confirm delete which i dont know how to do! :( i found a way to show that message and show a continue button, although it doesnt wanna do anything lol
December 11, 2010 at 1:16 pm #70008Hadley17
MemberI got it to work, i realized I had the part that check to see if the continue button was set inside the delete buttons code. I simply removed it and it worked. :)
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.