Page 1 of 1
Grid / Data Delete
Posted: Sat Jan 30, 2010 7:00 pm
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
Re: Grid / Data Delete
Posted: Sat Jan 30, 2010 9:18 pm
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
Re: Grid / Data Delete
Posted: Sat Jan 30, 2010 11:48 pm
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 ( } ).
Re: Grid / Data Delete
Posted: Sun Jan 31, 2010 2:00 pm
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.