Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End I need help with PHP delete form confirmation! ASAP

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30956
    Hadley17
    Member

    Hello 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!

    #70108
    TT_Mark
    Member

    I’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.

    #70038
    Hadley17
    Member

    exactly, 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..

    #70039
    rickylamerz
    Member

    Dear 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,
    Rick

    #70007
    Hadley17
    Member

    its 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

    #70008
    Hadley17
    Member

    I 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. :)

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.