I guess something must have changed in my servers PHP configuration. The webmaster indicated that they updated thier PHP install and now my program is not working. Here is my code:
Specifically, the $itemprice, $itemcost, $itemnumber and the $rs variables aren't showing a value when I log the value in the UpdateItem function. It seems like a problem with variable scope, but this was working before. Any ideas?
LJ
Code:
#!/usr/bin/php
<?php
include("clsDatabase.php");
include("clsDebug.php");
$spaces = '...................................................';
function NewItem() {
$db = new Database;
$bug = new Debug;
$itemdepartment = 'Rx ';
if ( $w_OTC_Flag != '' ) { $itemdepartment = "HBA"; }
if (( $w_OTC_Flag == '' ) and ( strlen($w_UPC) == 12 )) {
$itemdepartment = "HBA";
}
echo "abc_update: Added $itemnumber\n";
$sql = "INSERT INTO tblItems ("
."itemnumber, "
."itemdescription, "
."itemprice, "
."itemcost, "
."itemdepartment, "
."vendor, "
."qtyonhand, "
."value "
.") VALUES ( "
."'".$itemnumber."', "
."'".$db->SQLFixup($itemescription)."', "
."'".$itemretail."', "
."'".$itemcost."', "
."'".$itemdepartment."', "
."'ABC',0,0.00 "
.");";
$rs = $db->query($sql);
} // function New_Item
function UpdateItem() {
$db = new Database;
$bug = new Debug;
$CurrentItem = $db->fetch_array($rs);
$UpdateItem = $CurrentItem;
if (( $CurrentItem['itemcost'] != $itemcost ) or
( $CurrentItem['itemprice'] != $itemprice )) {
echo "abc_update: Updated $itemnumber\n";
$sql = "UPDATE tblItems set "
. "itemcost = $itemcost, "
. "itemprice = $itemprice "
. "WHERE itemNumber = '$itemnumber'";
$db->query($sql);
} // Update needed
} // function Update_Item
function ProcessUpdate( $filename ) {
$db = new Database;
$bug = new Debug;
$spaces = ' ';
if ( $filename == "" ) {
$bug->Fatal("abc_update: File name not specified");
} else {
$fh = fopen($filename,'r') or
$bug->Fatal("abc_update: Cannot open file: $filename");
}
$bug->Log("abc_update: Processing file: $filename");
while(!feof($fh)) {
$buf = fgetcsv($fh,0,"\t");
// =========== Get the fields
$vendoritemnumber = $buf[0]; // Vendor Item Number
$itemdescription = $buf[1]; // Description
$itemcost = $buf[2]; // Cost
$itemAWP = $buf[3]; // AWP
$vendorcode = $buf[4]; // Code
$itemNDC = $buf[5]; // NDC
$itemUPC = $buf[6]; // UPC
$item_GCN_SEQNO = $buf[7]; // GCN_SEQNO
$itemMAC = $buf[8]; // MAC
$itemOTC_Flag = $buf[9]; // OTC Flag
$itemprice = $buf[10]; // Retail Price
// Set the Item Number
if ($itemUPC != "" ) {
$itemnumber = $itemUPC; // Prefer UPC Code
} else {
$itemnumber = $itemNDC;
}
if ( $itemnumber == "" ) {
$msg = "abc_update: No Item Number for $itemdescription";
$bug->Log($msg);
} else {
// Check to see if the item is already in the database
$sql = 'SELECT * FROM tblItems WHERE itemNumber = "'.$itemnumber.'"';
$rs = $db->Query($sql);
$item = $db->fetch_array($rs);
if ( $item['itemprice'] != $itemprice ) {
$fill = 40 - strlen($item['itemdescription']);
echo $item['itemdescription']
. substr($spaces,1,$fill)
. ' Old Retail: '.number_format($item['itemprice'],2,'.',',')
. ' New Retail: '.number_format($itemprice,2,'.',',')
. "\n";
}
if ( $rs ) { // Update
UpdateItem();
} else { // New item
NewItem();
}
}
} // while not eof
fclose($fh);
} // function ProcessUpdate file.
// Main
ProcessUpdate("/var/spool/uucppublic/OTC.txt");
?>
Specifically, the $itemprice, $itemcost, $itemnumber and the $rs variables aren't showing a value when I log the value in the UpdateItem function. It seems like a problem with variable scope, but this was working before. Any ideas?
LJ