lastErrorMsg()); } $invoiceUpdatedNumber = $updatedData['invoiceUpdatedNumber']; $invoicefull = $updatedData['invoicefull']; $item = $updatedData['itemString']; $description = $updatedData['descriptionString']; $subtotalString = $updatedData['subtotalString']; $subtotal = preg_replace("/[^0-9.,]+/", "", $subtotalString); $totalvalue = $updatedData['totalvalue']; $createdate = $updatedData['createdate']; // Check for errors in the database connection if (!$db) { die("Database connection failed: " . $db->lastErrorMsg()); } // Retrieve data from the "inv" column in the "figures" table $query1 = $db->query('SELECT id, invoicefull FROM figures'); while ($row1 = $query1->fetchArray(SQLITE3_ASSOC)) { if ($invoicefull == $row1['invoicefull']) { $id = $row1['id']; $updateQuery1 = "UPDATE figures SET invoicefull = :invoiceUpdatedNumber WHERE id = :id"; $stmt1 = $db->prepare($updateQuery1); if (!$stmt1) { die("Prepare failed: " . $db->lastErrorMsg()); } $stmt1->bindValue(':invoiceUpdatedNumber', $invoiceUpdatedNumber, SQLITE3_TEXT); $stmt1->bindValue(':id', $row1['id'], SQLITE3_TEXT); $result1 = $stmt1->execute(); if (!$result1) { die("Execute failed: " . $db->lastErrorMsg()); } } } $invoicefull = $invoiceUpdatedNumber; // Prepare and execute the SQL UPDATE query $query2 = "UPDATE figures SET item = :item, description = :description, subtotal = :subtotal, totalvalue = :totalvalue, createdate = :createdate WHERE invoicefull = :invoicefull"; $stmt2 = $db->prepare($query2); if (!$stmt2) { die("Prepare failed: " . $db->lastErrorMsg()); } $invoicefull = $invoiceUpdatedNumber; $stmt2->bindValue(':item', $item , SQLITE3_TEXT); $stmt2->bindValue(':description',$description, SQLITE3_TEXT); $stmt2->bindValue(':subtotal', $subtotal, SQLITE3_TEXT); $stmt2->bindValue(':totalvalue', $totalvalue, SQLITE3_TEXT); $stmt2->bindValue(':createdate', $createdate, SQLITE3_TEXT); $stmt2->bindValue(':invoicefull', $invoicefull, SQLITE3_TEXT); $result2 = $stmt2->execute(); if (!$result2) { die("Execute failed: " . $db->lastErrorMsg()); } // Close the database connection and the prepared statement $stmt2->close(); $db->close(); $response = ['success' => $invoicefull]; echo json_encode($response); } else { $response = ['success' => false]; echo json_encode($response); } } ?>