SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I have this code to deletearticles from my mysql database. I have a script to list all the articles with a delete and edit link next to it. I'm afraid I'm going to hit the wrong link and delete the article. How can I make it so that I have to click on another link to delete the article?

    [code]$delete = mysql_query("DELETE FROM articles WHERE ID=$id");
    if ($delete) {
    echo("<P>Article deleted successfully!</P>");
    } else {
    echo("<P>Error deleting article from database!<BR>".
    "Error: " . mysql_error());

    }[code]

    Thanks,
    Justin Sampson

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the idea only:
    you specify an "action" variable, when the first time you hit it, that action should be something:

    $action = "open_confirm_box"

    then display the box for confirmation (use if/else statement) then in the confirmation page, your <FORM> will now say:

    $action = "user_confirmed"

    then use a branch of if/else to actually delete it.

    That is how I did. If someone has a better idea, just go ahead!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my way not saying its better but its how I doit using javascript:

    You have a form with the name theform

    like

    <form action="<? print $PHP_SELF; ?>" method="POST">

    Then you have your links instead of making the delete links hot make them look like

    <a href="#" onClick="confirmit('<? print $articlename ?>'); ">delete</a>

    Now for the javascript:

    put this in the head of the doc

    <script language="JavaScript">
    <!--
    function confirmit(articlename) {
    var agree = false;
    agree = confirm('Are you sure you want to permanently delete ' + articlename + ' from the database?');
    if (agree) {
    document.theform.submit();
    }
    else {
    return false;
    }
    }
    //-->
    </script>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yeah, I almost forget that client-side scripting could be handy!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although it won't keep people with javascript turned off from inadverntly deleting records but I think in justin's case it will work fine because it seems he will be the only one deleting records.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •