Ok I have asked sort of this same question before but using a different function and you all helped me GREATLY!! Now I am having an interesting issue trying to replicate but change the process. I am trying to send data into the main table but also send one field into a second table using beforeadd event.
Default code I am using
[codebox]function BeforeAdd(&$values)
{
// Parameters:
// $values - Array object.
// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Save new data in another table ****
global $conn,$strTableName;
$strSQLSave = "INSERT INTO AnotherTable (Field1, Field2) values (";
$strSQLSave .= $values["Field1"].",";
$strSQLSave .= $values["Field2"];
$strSQLSave .= ")";
db_exec($strSQLSave,$conn);
return true;
// return true if you like to proceed with adding new record
// return false in other case
}[/codebox]
Now my issue is when i use the default code for the "Save new data in another table" function everything works peachy if I am only using 1 field from each table.
ie.
[codebox]function BeforeAdd(&$values)
{
// Parameters:
// $values - Array object.
// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Save new data in another table ****
global $conn,$strTableName;
$strSQLSave = "INSERT INTO LDtotals (AISLensDoctor) values (";
$strSQLSave .= $values["LensDoctor"];
$strSQLSave .= ")";
db_exec($strSQLSave,$conn);
return true;
// return true if you like to proceed with adding new record
// return false in other case
}[/codebox]
So obviously the first thing you notice is I took out one of the fields from the source and one from the destination (to only move 1 field AND THIS WORKS FINE)
now when I try to use the same exact code but add the second field (just like it is defaulted to) I get errors.....
Technical information
Error type 2
Error description odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect
URL 208.49.238.91/blargh/output/AISTotals_add.php?
Error file C:\www\webroot\BLARGH\output\include\dbconnection.php
Error line 56
SQL query insert into [AISTotals]
Solution This is a general error. It occurs when there is an error in event code or in SQL.
Send your SQL or event code along with full error message tosupport@xlinesoft.com.
using this code
[codebox]function BeforeAdd(&$values)
{
// Parameters:
// $values - Array object.
// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Save new data in another table ****
global $conn,$strTableName;
$strSQLSave = "INSERT INTO LDtotals (Date, AISLensDoctor) values (";
$strSQLSave .= $values["Date"].",";
$strSQLSave .= $values["Lensdoctor"];
$strSQLSave .= ")";
db_exec($strSQLSave,$conn);
return true;
// return true if you like to proceed with adding new record
// return false in other case
}
[/codebox]
See how this is strange? maybe I am missing something simple but just wierd to me how it will work when I modify the code but using the exact default format (just changing table info) it messes up.