| Index
» Projects
» phpMyEdit
» Forum
» Delete trigger help please. |
 |
Hobb3s
Joined: 06 Jun 2007
Posts: 6
Posted: 2007-10-09 19:24
Back to top
Reply with quote
|
Hello, I've been attempting to get a delete trigger working, unsuccessfully and I've run out of ideas. I'm just not certain what I'm missing or where the error is. When I ask it to delete something I don't get any errors, it just goes back to displaying the database. The Filtering works properly for entries that I manually enter 1 for the deleted field.
TIA.
Here's what I have added to my configuration:
| Code: |
$opts['filters'] = 'PMEtable0.deleted = "0"';
$opts['filters'] = 'deleted is NULL or deleted = 0';
$opts['triggers']['delete']['before'] = 'categories.TDB.inc';
|
And then to the file I specified categories.TDB.inc the following:
| Code: |
<?php
$query2 = sprintf('UPDATE %s SET deleted = "1" WHERE %s = "%s"',
$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;
}
?> |
[/code]
|
michal
Joined: 17 Jun 2003
Posts: 537
Location: Slovakia
Posted: 2007-10-10 10:11
Back to top
Reply with quote
|
if your trigger succeded, you should return true (not false).
also, the two filters overvrite each other (the second one overwrites the first one).
|
Hobb3s
Joined: 06 Jun 2007
Posts: 6
Posted: 2007-10-11 13:47
Back to top
Reply with quote
|
I figured the filters were probably doing the exact same thing.
If I return true though, it deletes the database entry, which is contrary to the goal of keeping all the data and pretending it is deleted by filtering.
|
Hobb3s
Joined: 06 Jun 2007
Posts: 6
Posted: 2007-10-11 14:16
Back to top
Reply with quote
|
I've half figured it out. But now it it only takes the one with id 0, it seems that %d returns a 0 regarless of the record I choose. I don't entirely understand what the %s and %d represent. TIA.
Here is the code.
| Code: |
$query2 = sprintf('UPDATE %s SET deleted = 1 WHERE id = %d',
$this->tb, $newvals['id']);
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;
} |
|
Hobb3s
Joined: 06 Jun 2007
Posts: 6
Posted: 2007-10-11 19:10
Back to top
Reply with quote
|
Ok, at last it works. A few mods to the query.
| Code: |
$query2 = sprintf('UPDATE %s SET deleted = 1 WHERE %s = "%s"',
$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;
} |
That seems to work perfectly for my purpose. I hope this helps someone else.
|
|
Post new topic
Reply to topic
|
|
|
|