This topic is locked

Error Message Popup in Button

3/1/2023 11:36:47 PM
PHPRunner General questions
D
DRCR Dev author

Hi
This is my code for my botton (server section):
$record = $button->getCurrentRecord();
$result["md5"] = $record["md5"];
$result["user_id"] = $record["user_id"];
$result["filename"] = $record["filename"];
$result["year"] = $record["year"];
$result["period"] = $record["period"];
$md5 = $result["md5"];
$user_id = $result["user_id"];
$filename = $result["filename"];
$year = $result["year"];
$period = $result["period"];
// Fetch all rows that match the conditions and store them in $data1
$rs1 = DB::Query("SELECT * FROM import_transactions WHERE md5 = '".$md5."' AND user_id = ".$user_id." AND filename = '".$filename."' AND financial_year = '".$year."' AND financial_period = '".$period."'");
$data1 = array();
while ($row = $rs1->fetchAssoc()) {
$data1[] = $row;
}
$total = 0;
foreach ($data1 as $row) {
$total += $row["value"];
}
$total = round($total, 2);
if ($total == 0) {
`foreach ($data1 as $row) {
$user_id = $row["user_id"];
$financial_year = $row["financial_year"];
$financial_period = $row["financial_period"];
$date_posted = $row["date_posted"];
$date_document = $row["date_document"];
$type = $row["type"];
$nominal = $row["nominal"];
$value = $row["value"];
$vat = $row["vat"];

// Insert the row into the ledger table
$data = array();
$data["user_id"] = $user_id;
$data["financial_year"] = $financial_year;
$data["financial_period"] = $financial_period;
$data["date_posted"] = $date_posted;
$data["date_document"] = $date_document;
$data["type"] = $type;
$data["nominal"] = $nominal;
$data["value"] = $value;
$data["vat"] = $vat;
$res = DB::Insert("ledger", $data);
if (!$res) {
// Show an error message if there was an error inserting the row
echo "Error inserting row: ".DB::LastError();
return;
}
}

// Delete rows from the journals and import_transactions tables that match the conditions
$data = array();
$data["md5"] = $result["md5"];
$data["user_id"] = $result["user_id"];
$data["filename"] = $result["filename"];
$data["year"] = $result["year"];
$data["period"] = $result["period"];
DB::Delete("journals", $data );

$data = array();
$data["md5"] = $result["md5"];
$data["user_id"] = $result["user_id"];
$data["filename"] = $result["filename"];
$data["financial_year"] = $result["year"];
$data["financial_period"] = $result["period"];
DB::Delete("import_transactions", $data );} else { echo "<script>alert('Journal is not balanced!');</script>"; } Everything works fine except when this is triggered: else {

echo "<script>alert('Journal is not balanced!');</script>";

}
`The popup shows fine but I get a blank error after:
img alt
Am I using the correct code to generate the popup error? The error only happens when the popup is triggered.
Thanks in advance for any advice.
-Cec

admin 3/2/2023

You need to use Javascript to create popup windws. Do not use PHP for this purpose.