This topic is locked

Before Record Added-Save new data to another table

12/30/2006 1:04:40 AM
PHPRunner General questions
J
JZint author

I have two tables, inventory detail and equipment in stock. When I receive new inventory, I want to save a record of it to the equipment in stock table as well as when I send this inventory, I want to delete it out of the equipment table. I have been testing two of the fields, Customer and Salesman. I have managed to get it to create an entry in the equipment in stock table, but no information. Here is the code that I have used. I have tried every type of variable to get it to post the information to the fields, but with no luck.
function AfterAdd()

{

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

global $conn;

$strSQLInsert = "insert into _equipment_in_stock (Customer, Salesman) values (Customer, Salesman)";

db_exec($strSQLInsert,$conn);
}

Sergey Kornilov admin 12/30/2006

Use BeforeAdd event:

function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "insert into _equipment_in_stock (Customer, Salesman) values ('" . $values["Customer"]. "','" . $values["Salesman"] . "')";

db_exec($strSQLInsert,$conn);
return true;
// return true if you like to proceed with adding new record

// return false in other case
}


Make sure field names are correct.