I am working with 2 main tables. One is called assets and another is called transfer. The asset table holds data on assets. The transfer table is used to transfer assets. While the tables are different, they both have 3 fields in common. Those fields hold the location of the assets, department, address. The plan is that when an asset is transferred, an update statement would be used to take the new location from the transfer table and update the corresponding fields in the asset table.For this, i have tried row_inserting events of the transfer table. It updates the asset table, once i do not put a condition. However, once i add a condition which says to update the asset table if a field in the transfer table holds a certain value, i get the message “insert cancelled.” It no longer inserts values in the transfer table and therefore cannot update the assets table.Any assistance would be appreciated.
I was able to solve the Error issue, as it was a syntax error. However, please see the code below. It is to be executed if the value of the TransferApprovedBy field is Chairman, which is chosen from a dropdown box.It is completely ignoring the condition and executing the Updates. I have placed the code in the Row_Inserted event. I also tried it in the Row_Inserting as well as the Row_Updating event. Any advice?if ($this->TransferApprovedBy->CurrentValue == “Chairman”);Execute(“UPDATE assets SET Division='”.$rsnew[“TransferRequestTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Execute(“UPDATE assets SET Section='”.$rsnew[“SectionTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Execute(“UPDATE assets SET Address='”.$rsnew[“AddressTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Execute(“UPDATE assets SET RoomNumber='”.$rsnew[“RoomNumberTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Try this instead:if ($rsnew[“TransferApprovedBy”] == “Chairman”) {Execute(“UPDATE assets SET Division='”.$rsnew[“TransferRequestTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Execute(“UPDATE assets SET Section='”.$rsnew[“SectionTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Execute(“UPDATE assets SET Address='”.$rsnew[“AddressTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);
Execute(“UPDATE assets SET RoomNumber='”.$rsnew[“RoomNumberTo”].“’ WHERE AssetsID=”.$rsnew[“AssetsID”]);}
Made the change but it continues to ignore the conditions. When for example, I choose an option other than “Chairman” it still updates the asset table even though the condition states “chairman”.
Above this line:
if ($rsnew[“TransferApprovedBy”] == “Chairman”) {try to put this code:
$this-setMessage("TransferApprovedBy value is: " . $rsnew[“TransferApprovedBy”]);
return FALSE;and try again. Post the result in here for more discussion.
Results:Fatal error: Uncaught Error: Call to undefined function PHPMaker2019\ssaassetmgr\setMessage() in C:\wamp64\www\assetmgnt\classes\transfer.php on line 2351
( ! ) Error: Call to undefined function PHPMaker2019\ssaassetmgr\setMessage() in C:\wamp64\www\assetmgnt\classes\transfer.php on line 2351
Call Stack
Time
Memory
Function
Location
1
0.0017
429344
{main}( )
…\transferedit.php:0
2
0.1589
2608008
PHPMaker2019\ssaassetmgr\transfer_edit->run( )
…\transferedit.php:23
3
0.8937
3679320
PHPMaker2019\ssaassetmgr\transfer_edit->editRow( )
…\transfer_edit.php:762
4
1.8944
3726256
PHPMaker2019\ssaassetmgr\transfer_edit->Row_Updated( )
…\transfer_edit.php:2416
Hi Mobhar, it is working. I also had the following:if (CurrentPageID() == “edit”) // make sure only for Edit Page
if (CurrentUserLevel() == -1)I have commented them out and it works. However, I have no idea why these added conditions posed a problem.
Thanks so much for your kind and patient assistance.
mobhar wrote:
$this-setMessage("TransferApprovedBy value is: " . $rsnew[“TransferApprovedBy”]);Sorry, my fault. That code should be:
$this->setMessage("TransferApprovedBy value is: " . $rsnew[“TransferApprovedBy”]);morrellaberdeen wrote:
However, I have no idea why these added conditions posed a problem.That code above is actually for checking, to make sure the TransferApprovedBy field contains a value or not. That’s why below that code we have return FALSE.