Deleting Database Records
Don't delete database records. Try using a column named `deleted` with a default value of 0 and then and suppressing unwanted records by setting `deleted` to 1, and implementing both a trigger and a filter in your forms.
$opts['filters'] = 'PMEtable0.deleted = "0"';
// See also ./triggers/mark_as_deleted.TDB.inc
Create one of the following column definitions in a table, using phpMyAdmin, and set an INDEX for it:
`deleted` enum('0','1') NOT NULL default '0',
`deleted` tinyint(1) NOT NULL default '0',
`deleted` enum('N','Y') NOT NULL default 'N',
Defining the `deleted` field as tinyint(1) may be better because it is not language specific.
If the `deleted` column is found in your table, one of the following filters will be automatically added to the generated script.
$opts['filters'] = 'PMEtable0.deleted = "N"';
-or-
$opts['filters'] = 'PMEtable0.deleted = "0"';
Henceforth, instead of actually deleting the record from the table, an included trigger will flag records as deleted ('Y' or '1').
// Contents of ./output/triggers/mark_as_deleted.TDB.inc
$query2 = sprintf('UPDATE %s SET deleted = "1" WHERE %s = "%d"',
$this->tb, $this->key, $oldvals[$this->key]);
if($this->MyQuery($query2)){
return false;
}else{
echo "\n".'<p>'.mysql_error().'</p>';
echo "\n".'<a href="javascript:history.go(-1)"
onmouseover="self.status=document.referrer;return true">Go Back</a>';
exit;
}
Test this functionality for each table by adding a "junk" record, deleting it using the generated form, and checking the data table using phpMyAdmin to ensure the appropriate result was achieved.
View the Demo (new window).
PHP Form Generator Home
| PHP Form Generator Demo
|