|
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
require_once 'db.php';
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
$response = ["status" => "error", "message" => "Something went wrong."];
// Function to get existing data
function getExistingData($con) {
$stmt = $con->prepare("SELECT * FROM reset_email LIMIT 1");
$stmt->execute();
$result = $stmt->get_result();
return $result->fetch_assoc();
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$action = isset($_POST['action']) ? trim($_POST['action']) : '';
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
$des = isset($_POST['des']) ? trim($_POST['des']) : '';
$note = isset($_POST['gst']) ? trim($_POST['gst']) : '';
$des1 = isset($_POST['des1']) ? trim($_POST['des1']) : '';
$des2 = isset($_POST['des2']) ? trim($_POST['des2']) : '';
if (!empty($title) && !empty($des) && !empty($note) && !empty($des1) && !empty($des2)) {
try {
// Check if data exists
$existing = getExistingData($con);
if ($action === "Insert" && !$existing) {
// Insert new record
$stmt = $con->prepare("INSERT INTO reset_email (title, des, note, des1, des2) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $title, $des, $note, $des1, $des2);
} else {
// Update existing record
$stmt = $con->prepare("UPDATE reset_email SET title=?, des=?, note=?, des1=?, des2=? LIMIT 1");
$stmt->bind_param("sssss", $title, $des, $note, $des1, $des2);
}
if ($stmt->execute()) {
$data = getExistingData($con);
$response = [
"status" => "success",
"message" => ($action === "Insert" ? "Data inserted" : "Data updated") . " successfully!",
"data" => $data
];
} else {
throw new Exception("Execute failed: " . $stmt->error);
}
$stmt->close();
} catch (Exception $e) {
error_log("Database error: " . $e->getMessage());
$response = ["status" => "error", "message" => "Database error: " . $e->getMessage()];
}
} else {
$response = ["status" => "error", "message" => "All fields are required."];
}
} else if ($_SERVER["REQUEST_METHOD"] === "GET") {
// Return existing data
$data = getExistingData($con);
if ($data) {
$response = ["status" => "success", "data" => $data];
} else {
$response = ["status" => "error", "message" => "No data found"];
}
}
echo json_encode($response);
?>