I have looked at various examples of using values in a form to do "something else" besides just write directly to the table the form is based on.
The code examples in the PHPRunner manual don't seem to cover my situation exactly but I tried to do something with them which is failing in the ADD Page "After records added".
I have a master record with fields that I want to populate with data from the ADD form. I would like to collect some values from the Form and pass them along after the detail table is written to the Master table. I want these fields to UPDATE, I guess, the master table in its matching field values. Kill two birds with one stone. The PHPRunner examples show INSERT used more than anything so I have tried with INSERT.
So once the Details table is written to in the very next action I want selected values, either from the filled out fields in the form AS it is submitted, or taken from the details table just after a new record is added. So, I know that the values, I presume are referred to differently depending on whether I am retrieving them from the form once it is filled out, or from the table record where this form is saved.
Here is what I have tried and I get error messages even though the PHPRunner Syntax checker say the Syntax is okay--
Events file "After records added" activated on ADD page.
//** Save new data in another table ****
global $conn,$strTableName;
$strSQLSave = "INSERT INTO pharmacy_address (contact_titel, contact_academic_titel,contact_first_name,contact_second_name,contact_phone,contact_email) values (";
$strSQLSave .= $values["contact_titel"].",";
$strSQLSave .= $values["contact_academic_titel"].",";
$strSQLSave .= $values["contact_first_name"].",";
$strSQLSave .= $values["contact_second_name"].",";
$strSQLSave .= $values["contact_phone"].",";
$strSQLSave .= $values["contact_email"];
$strSQLSave .= WHERE ($keys["pharmacy_nr"] == $values["pharmacy_nr"]);
$strSQLSave .= ")";
db_exec($strSQLSave,$conn);
"
So, that version is failing on the "Where" with this error "Fatal error: Call to undefined function: where()"
In the following version with a different "where" it now fails even earlier----
And this next version where I am trying to use the values that are being submitted from the form to go write to the "pharmacy_address" Master table is also FAILING nicely!
I even tried a version using $postvalues instead of $values but so far I cannot make anything happen but errors.
This Action is my latest but it fails....
global $conn;
$strSQLInsert = 'UPDATE pharmacy_address
SET contact_titel
=$values["contact_titel"],contact_academic_titel
=$values["contact_academic_titel"],contact_first_name
=$values["contact_first_name"], contact_second_name
= $values["contact_second_name"],contact_phone
= $values["contact_phone"],contact_email
= $values["contact_email"] WHERE pharmacy_nr
= $values["pharmacy_nr"]' ;
db_exec($strSQLInsert,$conn);
It produces things like this after telling me it has a problem with the SQL--
0. include/dbconnection.php:36 db_query 1. UPDATE pharmacy_address
SET contact_titel
=$postvalues["contact_titel"],contact_academic_titel
=$postvalues["contact_academic_titel"],contact_first_name
=$postvalues["contact_first_name"], `conta...;
- Resource id #10;
1. include/dbconnection.php:47 db_exec 1. UPDATE pharmacy_address
SET contact_titel
=$postvalues["contact_titel"],contact_academic_titel
=$postvalues["contact_academic_titel"],contact_first_name
=$postvalues["contact_first_name"], `conta...;
- Resource id #10;
[size="4"]Here is the array that does keep being written successfully to the details table[/size]
These are the values from the Add page form that I am trying to retrieve and select some, but not all of them to write in a correctly sequentialed string to the same-named fields in the Master details table where the record with primary id "pharmacy_nr" matches the one submitted in this form.
- Array ( [detailer_id] => 1 [pharmacy_nr] => 40181983 [contact_titel] => 1 [contact_academic_titel] => 1 [contact_first_name] => Adam [contact_second_name] => Ant [contact_e...;
I want the pharmacy_nr value in the Add form to be the condition for a lookup in the "pharmacy_address" table so that just that specific record is modified or updated with those "pharmacy_nr" values which already exist as primary id's for each doctor record.
I would love an in-depth tutorial that shows how to take values from the Form itself when Saved or as it is being Submitted and save specific values to matching fields in another table where an associated record already exists.
Thank you greatly.