This topic is locked

Before Add Fuction

12/30/2006 2:29:12 PM
PHPRunner General questions
J
JZint author

I have a inventory detail table that I receive in the equipment. I also have a equipment in stock table that is for viewing only. When I bring in a piece of equipment, I am auto generating a Tag ID number. Using this function below, all of the information is transfering except the tag id. It seems to me that the reason that the Tag ID is not transfering is that the ID has not been created until after the entry is posted and I am posting to the equipment table before the post. I have tried to add after with the same code but I am getting a value error. Do I need to use a different format to get the values? I have inserted the code that I am using for the before add.
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 (Tag_ID, Customer, Salesman, Location_No, Part_No, Model_No, Serial_No, Color, Size, Description) values (

'".$values['Tag_ID']."',

'".$values['Customer']."',

'".$values['Salesman']."',

'".$values['Location_No']."',

'".$values['Part_No']."',

'".$values['Model_No']."',

'".$values['Serial_No']."',

'".$values['Color']."',

'".$values['Size']."',

'".$values['Description']."'

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

// return false in other case
}

Sergey Kornilov admin 12/31/2006

If you need to move the whole record including autoincrement field you need to use AfterAdd event.

When BeforeAdd event is executed record don't exist yet and autoincrement field value is not known.
Use something like this:

global $conn;

$strSQLInsert ="INSERT INTO _equipment_in_stock SELECT * from inventory_detail where Tag_ID = (select max(Tag_ID) from inventory_detail)";

db_exec($strSQLInsert,$conn);

J
JZint author 12/31/2006

Thanks for all of the help on my problems.