Row_Deleted Event Fails - No Record Found (v2018)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
neodaemon
User
Posts: 61

Row_Deleted Event Fails - No Record Found (v2018)

Post by neodaemon »

PHPMaker 2018.0.6

This is related to another post a long time ago, that I never was able to resolve.

I created a test project in order to have a clean slate and keep things very simple. I have one master table: 'registrations' with two detail tables: 'regdetails' and 'tbltmp'.
'tbltmp' stores records that have contributed detail about records in 'regdetails'.

STRUCTURE:

registrations
Column Type Comment
regid int(12) Auto Increment
fname varchar(200)
lname varchar(200)
emailaddress varchar(200)

regdetails
Column Type Comment
id int(12) Auto Increment
regid int(12)
prodid int(12)
prodname varchar(200)
prodattrib varchar(200)
prodtypeid int(12)
prodprice decimal(10,2)
qty int(12)
extprice decimal(10,2)
partcarid int(12)
caryearid int(12)
carmakeid int(12)
carmodelid int(12)
carbodyid int(12)
cartypeid int(12)
carclassid int(12)

tbltmp
Column Type Comment
id int(12) Auto Increment
regid int(12)
tmpname varchar(200)
tmpattrib varchar(200)

regdetails.prodattrib and tbltmp.tmpattrib have identical values.

When I delete a row from regdetails, I want the corresponding row from tbltmp (i.e. WHERE 'prodattrib' = 'tmpattrib') to be deleted.

I created this "Row_Deleted" event:

// Row Deleted event
function Row_Deleted(&$rs) {

	//echo "Row Deleted";
ew_Execute("DELETE FROM tbltmp WHERE tbltmp.tmpattrib = 401");
}

I did it this way to rule out any possible variables - and yes, tbltmp.tmpattrib = 401 really exists.
As a test, I entered the DELETE command straight into MySQL CLI and it works just fine.
In PHPMakerit results in "No Record Found".

If I turn on 'general_log' I see the "DELETE FROM tbltmp WHERE tbltmp.tmpattrib = 401" event fire, but it results in a roll back.
If I immediately enter the same DELETE query into CLI it works just fine.

Referential Integrity, as well as "Cascading Deletes" are all turned off.

No other errors in MySQL or Apache logs.

I'm really stumped and would appreciate any advice here.
Thank you


mobhar
User
Posts: 11727

Post by mobhar »

Change this:
ew_Execute("DELETE FROM tbltmp WHERE tbltmp.tmpattrib = 401");

to:
ew_Execute("DELETE FROM tbltmp WHERE tbltmp.tmpattrib = " . $rs["the_field_that_link_to_regdetails"] . ""); // adjust "the_field_that_link_to_regdetails" to the link field in regdetails


neodaemon
User
Posts: 61

Post by neodaemon »

WOW, that worked. Thank you very much!
Cheers


neodaemon
User
Posts: 61

Post by neodaemon »

FYI - the problem comes in when the two tables (i.e. "regdetails" and "tbltemp") are both presented on the "registrations" page as detail tables - BUT the "multiple detail tables" option is checked in the "Table Options". When the "multiple detail tables" box is checked, I get the "No records found" error - and no records are deleted. As soon as I uncheck that box, it works again.

Any idea why that might be?


Post Reply