This topic is locked
[SOLVED]

 Syntax Error on Insert record

8/17/2011 5:30:29 PM
PHPRunner General questions
B
bussb author

I'm struggling with a Syntax error on the code below. This code below is in the Add Record view, After Record Added event. I believe it has something to do with the ReportID which is an Integer value. The ReportID is the primary key of the record, which I want to take and insert into a tblmasterlog together with the [Type], [Created_By] and [Purpose] field names. All the other text (varchar) fields are inserting fine into the secondary table, but the ReportID is giving errors. Any assistance is greatly appreciated.
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "insert into tblmasterlog (Type, ReferenceID, Originator, Description)

values ('".$values["Type"]."', ".$values[Report_ID].", '".$values["Created_By"]."', '".$values["Purpose"]."')";

db_exec($strSQLInsert,$conn);
// Place event code here.

// Use "Add Action" button to add code snippets.

C
cgphp 8/17/2011

The quotes for the Report_ID key in the $values array are missing. Try out this code:

//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "insert into tblmasterlog (Type, ReferenceID, Originator, Description)

values ('".$values["Type"]."', ".$values["Report_ID"].", '".$values["Created_By"]."', '".$values["Purpose"]."')";

db_exec($strSQLInsert,$conn);



Be sure also that it is Report_ID and not ReportID.

B
bussb author 8/17/2011

This suggestion did resolve the issue. Thank you.