Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 10:21 am
by ricklincs
I have started to see the below error in my server logs:
Error 137.22.183.178 500 POST /wm/core/nuapi.php HTTP/1.0
this is closely followed by:
Error AH01071: Got error 'PHP message: PHP Fatal error: Cannot redeclare getForms() (previously declared in /var/www/vhosts/.../httpdocs/wm/core/nucommon.php(1408) : eval()'d code:3) in /var/www/vhosts/.../httpdocs/wm/core/nucommon.php(1408) : eval()'d code on line 2', referer: https://.../wm/
(... is the domain name)
My nubuilder app seems to perform ok, but now and again falls over on saving a new record.
I have looked in the After save code of the form I believe is causing this error and can see that no code has changed.
Has anyone else seen this happen or an idea of what is causing the above error messages.
Thanks in advance
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 11:44 am
by kev1n
Hi,
The error messages indicate that there is a PHP Fatal error related to the function getForms(). It seems that the function is being redeclared, causing conflicts in your code. Unfortunately, without additional details, it's challenging to pinpoint the exact cause of the error.
Here's a suggested improvement to address the issue:
Instead of declaring your function in the traditional way like this:
Code: Select all
function getForms() {
// code here
}
Consider using an anonymous function assigned to a variable, like so:
Code: Select all
$getForms = function() {
// code here
};
When you call the function, use the variable as follows:
This alternative declaration method might help mitigate the redeclaration issue you're facing.
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 12:18 pm
by ricklincs
Hi Kev1n
I am actually not calling function getForms() from any of my code. I have a form called SWISSPickNote
with the php code as After Save AS:
$sql = "UPDATE pickhead SET pickhead.status = 'PICKED' WHERE pickhead_id = '#RECORD_ID#' AND pickhead.status = ''";
nuRunQuery($sql);
//$sql1 = "UPDATE pickitems INNER JOIN pickhead ON pickitems.pickhead_id = pickhead.pickhead_id SET pickitems.pick_date = pickhead.pick_date, pickitems.pick_no = pickhead.pick_no, pickitems.complete = pickhead.complete WHERE pickitems.pickhead_id = '#RECORD_ID#'";
//nuRunQuery($sql1);
$sql1 = "UPDATE pickitems INNER JOIN pickhead ON pickitems.pickhead_id = pickhead.pickhead_id SET pickitems.pick_date = pickhead.pick_date WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql1);
$sql2 = "UPDATE pickitems INNER JOIN pickhead ON pickitems.pickhead_id = pickhead.pickhead_id SET pickitems.pick_no = pickhead.pick_no WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql2);
$sql3 = "UPDATE pickitems INNER JOIN pickhead ON pickitems.pickhead_id = pickhead.pickhead_id SET pickitems.complete = pickhead.complete WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql3);
$sql4 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.status = 'PICKED', stkbody.pick_date = pickitems.pick_date, stkbody.pick_no = pickitems.pick_no WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql4);
$sql5 = "INSERT into outhead(outhead_id, out_date, customer, company, out_no, order_no, delivery_date, haulier, deliver_to_company, delivery_address, delivery_address1, delivery_address2, delivery_pcode, notes, total_items, total_pcs, total_gross, total_nett, total_meters, status, pick_lookup, pick_product, pick_qty) SELECT pickhead_id, pick_date, customer, company, pick_no, order_no, delivery_date, haulier, deliver_to_company, delivery_address, delivery_address1, delivery_address2, delivery_pcode, notes, total_items, total_pcs, total_gross, total_nett, total_meters, 'OUT', pickhead_id, pick_product, pick_qty FROM pickhead WHERE pickhead.pickhead_id = '#RECORD_ID#' AND pickhead.complete = 'COMPLETE'";
nuRunQuery($sql5);
$sql6 = "UPDATE pickhead SET pickhead.status = 'OUT' WHERE pickhead_id = '#RECORD_ID#' AND pickhead.complete = 'COMPLETE'";
nuRunQuery($sql6);
//$sql7 = "INSERT INTO outitems(outitems_id, outhead_id, stkbody_id, unit_id_lookup, unit_id, product_code, product_description, basis_weight, width, diameter, gross, nett, qty, pcs, meters, buyers_ref, buyers_orderno, location, out_date, out_no, item_alias) SELECT pickitems_id, pickhead_id, stkbody_id, unit_id_lookup, unit_id, product_code, product_description, basis_weight, width, diameter, gross, nett, qty, pcs, meters, buyers_ref, buyers_orderno, location, pick_date, pick_no, item_alias FROM pickitems WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
//nuRunQuery($sql7);
$sql7 = "INSERT INTO outitems(outitems_id, outhead_id, stkbody_id, unit_id_lookup, unit_id, product_code, product_description, basis_weight, width, diameter, gross, nett, qty, pcs, buyers_ref, buyers_orderno, location, out_date, out_no, item_alias) SELECT pickitems_id, pickhead_id, stkbody_id, unit_id_lookup, unit_id, product_code, product_description, basis_weight, width, diameter, gross, nett, qty, pcs, buyers_ref, buyers_orderno, location, pick_date, pick_no, item_alias FROM pickitems WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
nuRunQuery($sql7);
$sql8 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.status = 'OUT' WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
nuRunQuery($sql8);
$sql9 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.aval_qty = stkbody.aval_qty - pickitems.qty WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql9);
$sql10 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.alloc_qty = stkbody.alloc_qty + pickitems.qty WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql10);
$sql11 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.aval_pcs = stkbody.aval_pcs - pickitems.pcs WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql11);
$sql12 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.alloc_pcs = stkbody.alloc_pcs + pickitems.pcs WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql12);
$sql13 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.pick_date = pickitems.pick_date WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql13);
$sql14 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.pick_no = pickitems.pick_no WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql14);
$sql15 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.issued_qty = pickitems.qty WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
nuRunQuery($sql15);
$sql16 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.issued_pcs = pickitems.pcs WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
nuRunQuery($sql16);
//$sql17 = "UPDATE pickhead SET pickhead.status = 'out' WHERE pickhead_id = '#RECORD_ID#' AND pickhead.status = 'COMPLETE'";
//nuRunQuery($sql17);
$sql18 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.alloc_pcs = stkbody.alloc_pcs - pickitems.pcs WHERE pickitems.pickhead_id = '#RECORD_ID#' and pickitems.complete = 'COMPLETE'";
nuRunQuery($sql18);
$sql19 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.alloc_qty = stkbody.alloc_qty - pickitems.qty WHERE pickitems.pickhead_id = '#RECORD_ID#' and pickitems.complete = 'COMPLETE'";
nuRunQuery($sql19);
$sql20 = "UPDATE pickhead SET pickhead.status = 'IN PROGRESS' WHERE pickhead_id = '#RECORD_ID#' AND pickhead.complete = 'IN PROGRESS'";
nuRunQuery($sql20);
$sql21 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.aval_gross = stkbody.aval_gross - pickitems.gross WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql21);
$sql22 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.aval_nett = stkbody.aval_nett - pickitems.nett WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql22);
$sql23 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.alloc_gross = stkbody.alloc_gross - pickitems.gross WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql23);
$sql24 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.alloc_nett = stkbody.alloc_nett - pickitems.nett WHERE pickitems.pickhead_id = '#RECORD_ID#'";
nuRunQuery($sql24);
$sql25 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.issued_gross = pickitems.gross WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
nuRunQuery($sql25);
$sql26 = "UPDATE stkbody INNER JOIN pickitems ON stkbody.stkbody_id = pickitems.stkbody_id SET stkbody.issued_nett = pickitems.nett WHERE pickitems.pickhead_id = '#RECORD_ID#' AND pickitems.complete = 'COMPLETE'";
nuRunQuery($sql26);
Thanks
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 1:16 pm
by kev1n
The function "getForms" is not present in nuBuilder's core code. To locate its declaration, consider generating a database dump and conducting a search within the dump. This will help identify the specific location where the function has been declared.
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 1:31 pm
by ricklincs
Thanks Kev1n will give a database dump a go. Thanks for your time.
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 3:04 pm
by kev1n
If you temporarily exclude the custom php code in BB of the form (or forms) that is causing a problem, does the error still occur?
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 4:03 pm
by ricklincs
I will give that a try.
I think this is code that is causing the problem (Before Browse) it is in a Lookup object on a subform.
// Get a unique list with form names
function getForms() {
$sql = "
SELECT DISTINCT item_id FROM stkbody WHERE customer = 'SWISS'
";
return $sql;
}
function getBase64JsonDTString($sql) {
$result = nuRunQuery($sql);
$a = [];
$a[] = '';
while ($row = db_fetch_row($result)) {
$a[] = $row;
}
return base64_encode(json_encode( $a ));
}
$w = getBase64JsonDTString(getForms());
$js = "
function getForms() {
return atob('$w');
}
";
nuAddJavascript($js);
//
;
Re: Error POST /wm/core/nuapi.php HTTP/1.0
Posted: Wed Jan 24, 2024 4:21 pm
by ricklincs
Thanks Kev1n that has worked a treat and now I am not getting any errors.