Best way to Insert via hook

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Best way to Insert via hook

Post by jimstoffel » 2018-10-10 15:13

Hello,

I've been trying to code with a hook file, more so the section "FILENAME_before_update(&$data, $memberInfo, &$args)" but doesn't work. My goal is to "copy data" from one table to another - before the fields get updated in the original table.

It isn't working in that the "filename" page comes up blank. My code in the hook file is:

$studid = '{$data['studentID']}';
$imm_data1 = '{$data['immunization_completed']}';
$imm_data2 = '{$data['immunization_additional']}';
$todaysdate = date("h:i:sa");

mysql_query("INSERT INTO student_immunization_info (studentid, immunization_completed, additional_immunizations) VALUES ('$studid', '$imm_data1', '$imm_data2')");

return true;

Am I to assume that the main reason is that the "hook code" is trying to "read" data that hasn't been pulled into the screen-view yet, because an "item" hasn't been selected?

If this is the case, what would you suggest as a better idea in copying data into a new table prior to an update?

Appreciate any comments/suggestions.

James.

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 519
Joined: 2018-04-01 10:12

Re: Best way to Insert via hook

Post by pböttcher » 2018-10-10 16:31

Hi,

can you try

Code: Select all

$studid = $data['studentID'];
$imm_data1 = $data['immunization_completed'];
$imm_data2 = $data['immunization_additional'];
$todaysdate = date("h:i:sa");

sqlvalue("INSERT INTO student_immunization_info (studentid, immunization_completed, additional_immunizations) VALUES ('$studid', '$imm_data1', '$imm_data2')");

return true;
The FILENAME_before_update should only be called on an update. So data should be filled (unless you clear all data :-) ).

jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Re: Best way to Insert via hook

Post by jimstoffel » 2018-10-10 17:19

Thank you for the suggestion, unfortunately that doesn't work.

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 519
Joined: 2018-04-01 10:12

Re: Best way to Insert via hook

Post by pböttcher » 2018-10-10 17:37

What happens? Can you post some more information?

jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Re: Best way to Insert via hook

Post by jimstoffel » 2018-10-10 17:56

As before, the FILENAME_info_view.php page comes up blank.

If I rem out the code, the page pops up as normal.

jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Re: Best way to Insert via hook

Post by jimstoffel » 2018-10-10 18:23

OK, I get my FILENAME_info_view.php back up by changing the code to:

$studid = $data['studentID'];
$imm_data1 = $data['immunization_completed'];
$imm_data2 = $data['immunization_additional'];
$todaysdate = date("h:i:sa");

mysql_query("INSERT INTO student_immunization_info (studentid, immunization_completed, additional_immunizations) VALUES ('$studid', '$imm_data1', '$imm_data2')");

return TRUE;

The NEW problem is now I get NO data to view. It says "No Matches Found"
Which makes me think that somehow the "Before_Update" function is pre-populating the 'studenid' field with BLANK.

Thoughts??

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 519
Joined: 2018-04-01 10:12

Re: Best way to Insert via hook

Post by pböttcher » 2018-10-10 18:35

Can you post a screenshot of this. Where is the message "No Matches Found" coming?

You select a record and change some values in the detail view and click the save button, correct?

Maybe you can explain what you try to acheive.

jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Re: Best way to Insert via hook

Post by jimstoffel » 2018-10-10 18:50

Again, in the FILENAME_info_view.php page, there should be a list of all the data in the database, however I get "No Matches Found" (see attachment). Which is why I think that the code in the "Before_Update" function is pre-populating the 'studenid' field with BLANK.
Attachments
test.png
test.png (5.54 KiB) Viewed 1028 times

jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Re: Best way to Insert via hook

Post by jimstoffel » 2018-10-10 18:52

I was under the impression that the &$data (array) would be populated once a record was selected but I think as the (hook) functions "loads" at page time, those 'data' fields are being pre-populated with BLANK based on my code.

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 519
Joined: 2018-04-01 10:12

Re: Best way to Insert via hook

Post by pböttcher » 2018-10-10 20:00

Hi,

sorry but I still do not get your workflow. At the top you add to the hook to the FILENAME_before_update which implies that you would handle your data in the FILENAME_view.
In your SQL you put the data into the table student_immunization_info.
In the last entry you access the FILENAME_info_view.

How are those related to each other?

jimstoffel
Posts: 17
Joined: 2017-01-13 02:43

Re: Best way to Insert via hook

Post by jimstoffel » 2018-10-11 14:07

My FILENAME_info_view.php is now working.
Had an error in my code in the 'before_update" section in the hook file (FILENAME_info_view.php) - missing a quote
All set. Appreciate all the help.

Post Reply