lastErrorMsg()); } // Prepare and execute the SQL UPDATE query $updateQuery = "UPDATE clients SET name = :name, mobile = :mobile, email = :email, address = :address, status = :status WHERE id = :id"; $stmt = $db->prepare($updateQuery); if (!$stmt) { die("Prepare failed: " . $db->lastErrorMsg()); } $stmt->bindValue(':name', $updatedData['name'], SQLITE3_TEXT); $stmt->bindValue(':mobile', $updatedData['mobile'], SQLITE3_TEXT); $stmt->bindValue(':email', $updatedData['email'], SQLITE3_TEXT); $stmt->bindValue(':address', $updatedData['address'], SQLITE3_TEXT); $stmt->bindValue(':status', $updatedData['status'], SQLITE3_TEXT); $stmt->bindValue(':id', $id, SQLITE3_INTEGER); $result = $stmt->execute(); if (!$result) { die("Execute failed: " . $db->lastErrorMsg()); } // Close the database connection and the prepared statement $stmt->close(); $db->close(); $invoicesDb = new SQLite3('database/invoices.db'); if (!$invoicesDb) { die("Invoices Database connection failed: " . $invoicesDb->lastErrorMsg()); } $clientid = $id; $sql = "SELECT * FROM figures WHERE clientid = :clientid"; $stmt2 = $invoicesDb->prepare($sql); if (!$stmt2) { die("Prepare failed: " . $invoicesDb->lastErrorMsg()); } $stmt2->bindValue(':clientid', $requestData['clientId'], SQLITE3_TEXT); $result = $stmt2->execute(); // Loop through the rows and update "clientname" to "PIET" while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $clientid = $row['clientid']; // Replace 'id' with the actual primary key column name if ($clientid == $id){ $clientname = $updatedData['name']; $mobile = $updatedData['mobile']; $email = $updatedData['email']; $address = $updatedData['address']; // Update the row $updateSql = "UPDATE figures SET clientname = :clientname, mobile = :mobile, email = :email, address = :address WHERE clientid = :clientid"; $updateStmt = $invoicesDb->prepare($updateSql); if (!$updateStmt) { die("Prepare failed: " . $invoicesDb->lastErrorMsg()); } $updateStmt->bindValue(':clientname', $clientname, SQLITE3_TEXT); $updateStmt->bindValue(':mobile', $mobile, SQLITE3_TEXT); $updateStmt->bindValue(':email', $email, SQLITE3_TEXT); $updateStmt->bindValue(':address', $address, SQLITE3_TEXT); $updateStmt->bindValue(':clientid', $clientid, SQLITE3_INTEGER); $updateStmt->execute(); } } // Close the invoices.db database connection and the prepared statement $stmt2->close(); $invoicesDb->close(); $projectsDb = new SQLite3('database/projects.db'); if (!$projectsDb) { die("Invoices Database connection failed: " . $projectsDb->lastErrorMsg()); } $sql3 = "SELECT * FROM projects WHERE clientid = :clientid"; $stmt3 = $projectsDb->prepare($sql3); if (!$stmt3) { die("Prepare failed: " . $projectsDb->lastErrorMsg()); } $stmt3->bindValue(':clientid', $requestData['clientId'], SQLITE3_TEXT); $result3 = $stmt3->execute(); while ($row3 = $result3->fetchArray(SQLITE3_ASSOC)) { $clientid = $row3['clientid']; // Replace 'id' with the actual primary key column name if ($clientid == $id){ $client = $updatedData['name']; // Update the row $updateSql3 = "UPDATE projects SET client = :client WHERE clientid = :clientid"; $updateStmt3 = $projectsDb->prepare($updateSql3); if (!$updateStmt3) { die("Prepare failed: " . $projectsDb->lastErrorMsg()); } $updateStmt3->bindValue(':client', $client, SQLITE3_TEXT); $updateStmt3->bindValue(':clientid', $clientid, SQLITE3_INTEGER); $updateStmt3->execute(); } } // Close the invoices.db database connection and the prepared statement $stmt3->close(); $projectsDb->close(); $response = ['success' => true]; echo json_encode($response); } else { $response = ['success' => false]; echo json_encode($response); } } ?>