Grid / Data Delete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zagato00
Forum Newbie
Posts: 1
Joined: Sat Jan 30, 2010 6:59 pm

Grid / Data Delete

Post by zagato00 »

i have a form i'd like to create that reads the values from a database and then it echos it to the screen, at the end of each row i need to place a "delete" button that only deletes that one record from the databae
any guidance would be helpful thank you
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Grid / Data Delete

Post by SimpleManWeb »

Well, as you are building your row, you should have all of your data in either an array or an object. So, I always use the ID of whatever my array/object is, and assign that to a link. Something like "BuildDataGrid.php?task=Delete&id=12". Then, you can use that information to build your delete call. Something like below:

Code: Select all

 
if (isset($_GET['task']) && $_GET['task'] == "Delete") {
   $SQL = "Delete from `TableName` where `id` = '".$_GET['id']."'";
   $Result = mysql_query($SQL);
}
 
//Then you put all of your code for building your table/grid.
 
 
Hope this helps
stuartshields
Forum Newbie
Posts: 10
Joined: Sat Jan 30, 2010 8:59 pm
Location: Toowoomba

Re: Grid / Data Delete

Post by stuartshields »

IF your pulling data from the db in a while loop, you should be able to do what the above post states. So before your while loop closing bracket ( } ).
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Grid / Data Delete

Post by AbraCadaver »

SimpleManWeb wrote:Well, as you are building your row, you should have all of your data in either an array or an object. So, I always use the ID of whatever my array/object is, and assign that to a link. Something like "BuildDataGrid.php?task=Delete&id=12". Then, you can use that information to build your delete call. Something like below:

Code: Select all

 
if (isset($_GET['task']) && $_GET['task'] == "Delete") {
   $SQL = "Delete from `TableName` where `id` = '".$_GET['id']."'";
   $Result = mysql_query($SQL);
}
 
//Then you put all of your code for building your table/grid.
 
 
Hope this helps
You need to put some form of delete confirmation that submits the delete operation as a POST request. You shouldn't perform any action other than retrieval with a GET operation.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply