I needed to add a small query to the previous code I posted help for, but this time it is to update the inventory as parts get check out.
The full code is this:
session_start();
//Define Session Variables
$User = $_SESSION['UserID'];
//Set the Static Variables
$TDID = '5'; //Checkout is 2 in the database
$mysqldate = date('Y-m-d H:i:s');
//Connection script to the server
$weberp = mysql_connect($hostname_weberp, $username_weberp, $password_weberp)
or die('Could not connect: ' . mysql_error());
//select database
mysql_select_db($database_weberp, $weberp);
//Select The database
$bool = mysql_select_db($database_weberp, $weberp);
if ($bool === False){
print "can't find $database_weberp";
}
$query = "SELECT
TempCart.ProductID,
TempCart.UnitsCheckOut,
TempCart.UserID,
TempCart.PartName,
TempCart.PartNumber,
TempCart.WOReference,
TempCart.VISA,
TempCart.PONumber,
TempCart.PMNumber
FROM
TempCart
WHERE
TempCart.UserID = '$User'";
//process the result
$result = mysql_query($query, $weberp);
//check for errors on the result
if(!$result){
die("SQL Query ERROR! " . mysql_error()); // if the result is not a proper result then we output the error
}
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
//Set each line to a variable
$ProductID = $row['ProductID'];
$PartName = $row['PartName'];
$PartNumber = $row['PartNumber'];
$WONumber = $row['WOReference'];
$UnitsCheck_In_Out = $row['UnitsCheckOut'];
//Run the Parts update
$PartsUpdate = "UPDATE
stockParts
SET
UnitsOnHand = UnitsOnHand-'$UnitsCheck_In_Out'
Where
PartNumber = '$ProductID'
";
$InsertPartsUpdate = mysql_query($PartsUpdate, $weberp); // This is the Standard Search
if(!$InsertPartsUpdate){
die("SQL Insert Query ERROR! this is the printout <br> $InsertPartsUpdate <br> " . mysql_error($weberp) ); // if the result is not a proper result then we output the error
}
//Run the insert Query
$InsertFinal = "INSERT INTO
PartsTransactions(
ProductID,
TDID,
UnitsCheck_In_Out,
UserId,
WONumber,
TransactionDateTime)
VALUES(
'$ProductID',
'$TDID',
'$UnitsCheck_In_Out',
'$User',
'$WONumber',
'$mysqldate'
)";
$InsertResult = mysql_query($InsertFinal, $weberp); // This is the Standard Search
if(!$InsertResult){
die("SQL Insert Query ERROR! this is the printout <br> $InsertFinal <br> " . mysql_error($weberp) ); // if the result is not a proper result then we output the error
}
}
//Create Delete of Temptable Query
$DELETE = "DELETE
FROM
TempCart
WHERE
TempCart.UserID = '$User'";
//Execute Delete Query
$resultDelete = mysql_query($DELETE, $weberp); // This is the Standard Search
if(!$resultDelete){
die("SQL Query ERROR! this is the printout <br> $DELETE <br> " . mysql_error($weberp) ); // if the result is not a proper result then we output the error
}
//unset Sessions
unset($_SESSION['POWOPMVS']);
but my problem is in the math query for the update:
//Run the Parts update
$PartsUpdate = "UPDATE
stockParts
SET
UnitsOnHand = UnitsOnHand-'$UnitsCheck_In_Out'
Where
PartNumber = '$ProductID'
";
$InsertPartsUpdate = mysql_query($PartsUpdate, $weberp); // This is the Standard Search
if(!$InsertPartsUpdate){
die("SQL Insert Query ERROR! this is the printout <br> $InsertPartsUpdate <br> " . mysql_error($weberp) ); // if the result is not a proper result then we output the error
}
the page does not return any errors, and when I print the query to see the output is showing the correct values to do the math. I tried the query in mysql and it works as it should. But when executed in PHP it simply does not update the values in the database.
Any ideas anyone?
Thanks,
Patrick J

New Topic/Question
Reply



MultiQuote




|