MMCT TEAM
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/public_html/ettgroups/../sbm/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/public_html/ettgroups/../sbm/admin/edit_price.php
<?php
session_start();
if (!isset($_SESSION['admin'])) {
  header("Location: index.php");
  exit();
}

  
  $host = "localhost";
$user = "u915722082_Info_sbm";
$pass = "sbm@TDS2025";
$db = "u915722082_sbm";
//   $conn = new mysqli("localhost", "u915722082_Info_sbm", "sbm@TDS2025", "u915722082_sbm");
// DB Connection
// $host = "localhost";
// $user = "root";
// $pass = "";
// $db = "sbm";

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$id = $_GET['id'] ?? null;
if (!$id) {
  echo "Missing ID";
  exit();
}

// Fetch existing price
$stmt = $conn->prepare("SELECT * FROM prices WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if (!$row) {
  echo "Price not found!";
  exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Edit Price</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body {
      background-color: #f8f9fa;
    }
    .sidebar {
      height: 100vh;
      background-color: #1e293b;
      color: white;
      padding-top: 1rem;
      position: fixed;
      width: 250px;
    }
    .sidebar a {
      color: #cbd5e1;
      display: block;
      padding: 10px 20px;
      text-decoration: none;
    }
    .sidebar a:hover {
      background-color: #334155;
    }
    .header {
      background-color: #ffffff;
      padding: 1rem;
      margin-left: 250px;
      border-bottom: 1px solid #e5e7eb;
    }
    .main-content {
      margin-left: 250px;
      padding: 2rem;
    }
    .captcha-display {
      background-color: #f3f4f6;
      border: 1px solid #d1d5db;
      border-radius: 6px;
      padding: 12px;
      text-align: center;
      font-family: monospace;
      font-size: 16px;
      font-weight: 600;
      letter-spacing: 2px;
      margin-bottom: 12px;
      color: #374151;
      user-select: none;
    }
  </style>
</head>
<body>

<!-- Sidebar -->
<div class="sidebar">
  <h4 class="text-center mb-4">Admin Panel</h4>
  <a href="price.php">Price</a>
  <a href="logout.php" class="text-danger">Logout</a>
</div>

<!-- Header -->
<div class="header d-flex justify-content-between align-items-center">
  <h5 class="mb-0">Welcome, <?php echo $_SESSION['admin']; ?></h5>
  <a href="logout.php" class="btn btn-outline-danger btn-sm">Logout</a>
</div>

<!-- Main Content -->
<div class="main-content">
  <div class="row mt-5 justify-content-center">
    <div class="col-md-6">
      <div class="card shadow-sm border-0">
        <div class="card-body">
          <h5 class="card-title">Edit Price</h5>

          <form method="POST" action="" id="priceForm">
            <input type="hidden" name="id" value="<?= $row['id']; ?>">

            <!-- Price Field -->
            <div class="mb-3">
              <label for="price" class="form-label">Price</label>
              <input type="number" step="0.01" class="form-control" id="price" name="price" value="<?= $row['price']; ?>" required>
            </div>

            <!-- CAPTCHA Display -->
            <div class="mb-3">
              <label class="form-label">CAPTCHA</label>
              <div class="captcha-display" id="captchaText"></div>
              <input type="text" class="form-control" id="captchaInput" name="captcha_input" placeholder="Enter CAPTCHA" required>
              <input type="hidden" id="hiddenCaptcha" name="generated_captcha">
            </div>

            <!-- Submit Button -->
            <button type="submit" class="btn btn-primary">Update Price</button>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
function generateCaptcha() {
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let captcha = '';
  for (let i = 0; i < 6; i++) {
    captcha += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  $('#captchaText').text(captcha);
  $('#hiddenCaptcha').val(captcha);
}

$(document).ready(function () {
  generateCaptcha();

  $('#priceForm').submit(function (e) {
    e.preventDefault();

    $.ajax({
      url: 'update_price.php',
      method: 'POST',
      data: $(this).serialize(),
      dataType: 'json',
      success: function (response) {
        if (response.status === 'success') {
          Swal.fire({
            icon: 'success',
            title: 'Updated!',
            text: response.message,
            timer: 2000,
            showConfirmButton: false
          }).then(() => {
            window.location.href = 'price.php';
          });
        } else {
          Swal.fire({
            icon: 'error',
            title: 'Error!',
            text: response.message
          });
          generateCaptcha(); // regenerate captcha on error
        }
      },
      error: function () {
        Swal.fire({
          icon: 'error',
          title: 'Oops...',
          text: 'Something went wrong!'
        });
      }
    });
  });
});
</script>

</body>
</html>

MMCT - 2023