Skip to main content
Known Participant
October 7, 2009
Question

How to delete a record from the database

  • October 7, 2009
  • 1 reply
  • 1331 views

I have created an insert record page as well as a search page, search results page and details page. But how can I delete a record from the website. I'm working with PHP MySQL. I tried to use the delete record behavior but not sure how to make this work. I tried to follow the Dreamweaver help file but it doesn't explain the settings. I added the behavior to a details page with a form button I named delete record just like in the help file and set the page to go to when delete is complete. When I test this page I click my delete record button and it just refreshes the page. No deletion is made and the page I told it to go to doesn't appear.

This topic has been closed for replies.

1 reply

Lawrence_Cramer
Inspiring
October 7, 2009

I'm not a PHP guy (CF)  but the SQL is the same...

DELETE FROM tablename

WHERE record-ID-field-name = recordID-URLvariable

You should surround the delete query in an "if" statement that makes sure a url variable has been passed. If it has, run the query, then - after the query has run - do another query to pull the current data from the table and display it.

Be sure you are pulling the data after the delete query runs or else the data you are displaying will not reflect the delete action.

Hope this helps.

--
Lawrence   *Adobe Community Expert*
www.Cartweaver.com
Complete Shopping Cart Application for
Dreamweaver, available in ASP, PHP and CF
www.twitter.com/LawrenceCramer

joe955Author
Known Participant
October 7, 2009

I'm completely lost on what page needs to do what now. I don't even think I know what page I insert the delete record behavior on. The help just says to use it while involving 4 pages. But unclear what page needs it. I have read some other posts which refer to having a detail page and a delete page. I guess the delete page would carry the delete behavior but nothing seems to jump out and say here is what to do. I mean a master page connected to the detail page then ? connected to the ? somwhere in between is the delete behavior = no more record in the database. I have been sent on a wild goose chase and I'm not sure whats right and whats wrong with this. I have never seen an option to delete from the table. I don't know what you mean. The db table or the table on a webpage?

Lon_Winters
Inspiring
October 8, 2009

It sounds like you're on the right track.  It works very simiilar to the details page.  You first create a recordset based on a value sent from the master results page.  You appley the Delete Behavior and select the recordset that you just created, and specify a confirmation page.

If it's just going back to itself, make sure the form action contains the <%=MM_editAction%> and the enctype is blank.