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.
Best way to Insert via hook
Re: Best way to Insert via hook
Hi,
can you try
The FILENAME_before_update should only be called on an update. So data should be filled (unless you clear all data ).
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;
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Posts: 22
- Joined: 2017-01-13 02:43
Re: Best way to Insert via hook
Thank you for the suggestion, unfortunately that doesn't work.
Re: Best way to Insert via hook
What happens? Can you post some more information?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Posts: 22
- Joined: 2017-01-13 02:43
Re: Best way to Insert via hook
As before, the FILENAME_info_view.php page comes up blank.
If I rem out the code, the page pops up as normal.
If I rem out the code, the page pops up as normal.
-
- Posts: 22
- Joined: 2017-01-13 02:43
Re: Best way to Insert via hook
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??
$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??
Re: Best way to Insert via hook
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.
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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Posts: 22
- Joined: 2017-01-13 02:43
Re: Best way to Insert via hook
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 (5.54 KiB) Viewed 4198 times
-
- Posts: 22
- Joined: 2017-01-13 02:43
Re: Best way to Insert via hook
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.
Re: Best way to Insert via hook
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?
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?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- Posts: 22
- Joined: 2017-01-13 02:43
Re: Best way to Insert via hook
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.
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.