Page 1 of 1

After insert not working 24.10

Posted: 2024-03-04 14:36
by omackeytech
I have a database in AP that worked till 24.10 upgrade.
I run the app and when I add a new record I get this error -
Query:
INSERT INTO `Actions`(`P_Record_ID`, `Name`, `Description`, `Location`, `Context`, `Due_Date`, `Source_Table`, S_Record_ID)
SELECT `P_Record_ID`, `Name`, `Description`, `Location`, `Context`, `Due_Date`, 'Tools_Needed', ''
FROM `Tools_Needed` t
WHERE t.ID =
Notice that right after 'Tools_Needed' the field is null also after' WHERE t.ID ='. That's supposed to be the PK. I looked in the database with PHP Admin and the record doesn't exist. I use the identical code for 'after update' and it works. Of course, the record is in the database anyway using UPDATE.

To me it looks like it's not inserting the record before calling the function 'after insert'.

Any thoughts?
Or is my code wrong?

Code: Select all

	function Tools_Needed_after_insert($data, $memberInfo, &$args) {
		$myID = $data['selectedID];
		$S_Record_ID = $myID;
		$Tn = "Tools_Needed";
		If ($data['Context'] != "") {sql("INSERT INTO `Actions`(`P_Record_ID`, `Name`, `Description`, `Location`, `Context`, `Due_Date`, `Source_Table`, S_Record_ID)
			SELECT `P_Record_ID`, `Name`, `Description`, `Location`, `Context`, `Due_Date`, '$Tn', '$myID' 
			FROM `Tools_Needed` t
			WHERE t.ID = $myID", $eo);
			}
		
		return TRUE;

Re: After insert not working 24.10

Posted: 2024-03-04 14:52
by jsetzer
Did you check for SQL errors in admin area?

Your insert statement contains a constant S_Record_ID which, as far as I can see, is undefined. I guess you mean a variable $S_Record_ID instead.

If there are no SQL errors, are you sure there are no new records in DB? Or maybe you just cannot see them in browser because you did not set_record_owner for the newly inserted records.

Re: After insert not working 24.10

Posted: 2024-03-04 18:53
by omackeytech
Js,

The S_Record_ID is a column in the 'actions' table. I probably should remove the reference to '$S_Record_ID' since I stopped using it. I just use the '$myID' instead.

The admin log shows the same error. Under the string I see this "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 4 " Line 4 is where I reference the 'Tools_Needed' row '$myID' (Pk).

What I'm trying to do is copy the inserted records ID to the 'actions' table so I can refer back to the 'Tools Needed' Table when the row in the actions table is deleted.

Thanks for your help.
Brian

Re: After insert not working 24.10

Posted: 2024-03-05 04:00
by jsetzer
$myID = $data['selectedID];
There is a single quote missing.