SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Deleting items

  1. #1
    SitePoint Zealot gregs's Avatar
    Join Date
    Aug 2002
    Posts
    161
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Deleting items

    Say I have a page that lists stories and each has a delete selector at the end, what would be the best way to go about deleting them? Should I make a new .php page and send it the information via the url?id=# or what?

    I thought about sending it via the URL and the DELETE page asking if I was sure I wanted to delete it or not. Would it be possible to actually delete something from the page it is on and not use another?

    Also, if making a delete page, would it be best to make it interactive with more than one pages deletes, via the ID number?

    For example:

    stories.php looks like so
    ID Title
    1 My first story [Delete]
    2 My second story [Delete]

    authors.php looks like so
    ID Author
    1 Ima Writer [Delete]

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    just send yourself back to the same page with a URL extension

    www.mysite.com/stories.php?delete=xyz&auth=pqr

    then put a catch in top of your page to handle the deletion of record XYZ from the database. The page then continues to load with the new data.

    If the page is not private, you should also send an auth code with the delete, this makes sure that the request has originated from your page, and isnt someone just randomly deleting your data. pqr would be a code that proves the request came from your page.

    You could put a javascript allert in there "Are You Sure?" just in case someone hits the link by mistake

    Other things to consider, a deleted author may require one or more books to be deleted at the same time. Also vice versa, if the last book from an author is deleted will you want that Author deleted at the same time.

    Unless there is a real good reason why not, Id consider combining stories.php and authors.php into one page and using PHP to decide which data is going to be displayed.

    PS like the avatar
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Zealot gregs's Avatar
    Join Date
    Aug 2002
    Posts
    161
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I had thought about using a javascript kind of popup, but are those kind of scripts dangerous?

    I was just asking if it is best to make an entirely different page to delete things or try to keep the function on the same page.

    Honestly, the way you described it confused me. Can't passing things via the Url be dangerous also?

    I just have this large program I wrote years ago when I was first learning PhP. It all works, but it needs a lot of cleaning and updating. I don't imagine anyone else has ever looked back at some of their old code and thought "What an awful mess!"

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The worst that can happen with a javascript confirm is that your visitor has JS disabled, you can and should check for that at the start of the page, then offer an alternative verification method.

    I always advocate keeps functionality local to one page, why have 100 pages when 10 will do? So if you are keeping authors.php and scripts.php seperate

    my authors page would handle
    Adding authors
    Deleting authors
    Viewing authors
    Editing authors

    and the stories.php the same 4 options

    Reread my first mail regarding the auth code, theres your safety in passing the delete in the URL

    Every programmer looks back at earlier scripts and hides under the table, if we didnt we wouldnt be learning newer and better techniques and wouldnt be improving, would we.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •