Evan,
where do you use this code?
Here:
function BeforeAdd(&$values)
{
global $conn;
// Parameters:
// $values - Array object.
// Each field on the Add form represented as 'Field name'-'Field value' pair
$_SESSION['send_customer'] = $values['Customer_ID'];
$_SESSION['send_part'] = $values['Product'];
$_SESSION['send_serial'] = $values['Serial_Number'];
//Find Transaction ID from Transaction
$strTID = "select `ID` from `_transactio`n where `Transaction_Name` = \"".$values['Type']."\"";
$rsTID = db_query($strTID, $conn);
$dataTID = db_fetch_numarray($rsTID);
$tID = $dataTID[0];
//Find Product ID from RA Products
$strPID = "select `product_id` from `ra_products` where `part_number` = \"".$values['Product']."\"";
$rsPID = db_query($strPID, $conn);
$dataPID = db_fetch_numarray($rsPID);
$pID = $dataPID[0];
//Retrieve Last Items ID
$strItemID = "select max(item_id) from `items`";
$rsItem = db_query($strItemID, $conn);
$dataItem = db_fetch_numarray($rsItem);
$itemID = ++$dataItem[0];
//split up all serials inside text area into array
$serialArray = explode("\n", $values["Serial_Number"]);
//trim strings inside array
for($i = 0; $i < count($serialArray); $i++)
{
trim($serialArray[$i]);
}
for($i = 0; $i < count($serialArray); $i++)
{
//try to find item_id in Items table
$strSearchID = "select `item_id` from `items` where `serial_number` = \"" . $serialArray[$i] . "\"";
$rsSearchID = db_query($strSearchID, $conn);
$dataSearchID = db_fetch_numarray($rsSearchID);
$searchID = $dataSearchID[0];
if($searchID)
{
//if item_id exist, only add new entry to items transactions
$strSQLInsert = "insert into itemtransaction (item_id, date, transaction_id, customer_id, location_name) values (".$searchID.",\"".now()."\", '".$tID."', '".$values['Customer_ID']."', '".$values['Location_Name']."')";
db_exec($strSQLInsert,$conn);
}
else
{
//if item_id does not exist, add new entry into Items and items transactions
$strInsertSerial = "insert into items (item_id, product_id, serial_number) values (" . $itemID . ", " . $pID . " ,\"" . $serialArray[$i] . "\")";
db_exec($strInsertSerial, $conn);
$strSQLInsert = "insert into itemtransaction (item_id, date, transaction_id, customer_id, location_name) values (".$itemID.",\"".now()."\", '".$tID."', '".$values['Customer_ID']."', '".$values['Location_Name']."')";
db_exec($strSQLInsert,$conn);
$itemID++;
}
}
//** Redirect to another page ****
header("Location: _Send_Receive_Report_view.php?var1=".$_SESSION['Customer ID']."&var2=".$_SESSION['Product']."&var3=".$_SESSION['Serial Number']);
exit();
return false;
// return true if you like to proceed with adding new record
// return false in other case
}
Cheers,
Evan