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
Grid / Data Delete
Moderator: General Moderators
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: Grid / Data Delete
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:
Hope this helps
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.
-
stuartshields
- Forum Newbie
- Posts: 10
- Joined: Sat Jan 30, 2010 8:59 pm
- Location: Toowoomba
Re: Grid / Data Delete
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 ( } ).
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Grid / Data Delete
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.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:
Hope this helpsCode: 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.
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.