?
Solved

Option to delete rows from sql database

Posted on 2013-01-14
3
Medium Priority
?
279 Views
Last Modified: 2013-01-20
Hello Experts.

I have a php page that displays in an html table all the rows from a database table.

I would like to add the option to delete a given row in my php page.

Here is an image to illustrate, I have already the table, just need another column with the respetive delte row option.

delete
In other question, @Ray_Paseur helped me to organize the contents but he said something about the delete option that I want you to consider:

In order to delete a row or a set of rows from the data base table, 
you will need to make a POST-method request to a script that runs a 
DELETE query.  The common design pattern for something like what 
you've shown here goes this way (sorry there is not a simple answer).

The "X delete entry" column contains a link to a delete script.  
The link looks like this URL:

<a href="delete.php?q=$id">delete</a>



In that URL, the $id variable is the key of the data base row to be deleted. 
When the script is started via a click on the link, it is started via a GET request.  
The variable $_GET['q'] contains the id.  The script will use the id to SELECT the 
row and display some of its information, perhaps the company name, along with the 
question, "Do you really want to delete?"  Below the question will be an HTML 
submit control that makes a POST method request to the deletion script, passing 
the id.  The DELETE query will have a WHERE clause that identifies the target 
row and a LIMIT clause that sets the query to remove only one row.

The nature of the "delete" option is a little complicated.  You need to understand 
the HTTP protocols to know why a POST request is required, but an example might help.  
Imagine if you had a delete script that used the GET method request.  In a GET request, 
the request information is transmitted in the URL variable.  If a script made a DELETE 
query on the basis of the URL variable alone, there would be a risk, to say the least.  
Now imagine what will happen when Google visits your page and tries to index all of 
the links.  Poof!  All rows are gone.

Open in new window



I am sure that he is right about this, but for example in a CMS like wordpress, there is a delete option for posts for instance, it's something silimar that I need.

Could you give me some hints on how to acomlish this delete option?

Thanks a lot.
0
Comment
Question by:joao_c
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38777182
Could you post the page php code that displays the table ?
0
 

Accepted Solution

by:
joao_c earned 0 total points
ID: 38778823
Thanks for the reply, here is the php page:

I ended up using code from: http://freezecoders.com/2012/11/add-list-edit-delete-record-in-database-using-php.html
0
 

Author Closing Comment

by:joao_c
ID: 38798090
I found the solution elsewhere.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question