setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo json_encode(['error' => 'Database connection failed: ' . $e->getMessage()]); exit(); } // Check if the request is a POST request if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get the data from the POST request $id = $_POST['id'] ?? ''; $projectname = $_POST['projectname'] ?? ''; $invoicedate = $_POST['invoicedate'] ?? ''; $movevalue = $_POST['movevalue'] ?? ''; $invoiceid = $_POST['invoiceid'] ?? ''; $type = $_POST['type'] ?? ''; $totalvalue = $_POST['totalvalue'] ?? ''; // Prepare update statement $stmt = $db->prepare('UPDATE invoices SET projectname = :projectname, invoicedate = :invoicedate, movevalue = :movevalue, invoiceid = :invoiceid, type = :type, totalvalue = :totalvalue WHERE id = :id'); // Bind parameters $stmt->bindParam(':projectname', $projectname); $stmt->bindParam(':invoicedate', $invoicedate); $stmt->bindParam(':movevalue', $movevalue); $stmt->bindParam(':invoiceid', $invoiceid); $stmt->bindParam(':type', $type); $stmt->bindParam(':totalvalue', $totalvalue); $stmt->bindParam(':id', $id); // Execute the SQL statement if ($stmt->execute()) { echo json_encode(['status' => 'success', 'message' => 'Row updated successfully!']); } else { echo json_encode(['status' => 'error', 'message' => 'Failed to update row!']); } } else { echo json_encode(['error' => 'Invalid request method.']); } // Close database connection $db = null; ?>