diff options
Diffstat (limited to 'paid.php')
-rw-r--r-- | paid.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/paid.php b/paid.php new file mode 100644 index 0000000..ec7e89a --- /dev/null +++ b/paid.php @@ -0,0 +1,50 @@ +<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Qarz daftarcha</title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
+ <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
+</head>
+<body>
+
+<div class="container mt-5">
+ <h2>Toladi</h2>
+ <form method="post" action="">
+ <div class="form-group">
+ <label for="miqdor">Pul:</label>
+ <input type="number" min="0" class="form-control" id="miqdor" placeholder="10000" name="miqdor">
+ </div>
+ <button type="submit" class="btn btn-primary">Saqlash</button>
+ </form>
+</div>
+
+<?php
+
+include "get_users.php";
+
+$id = $_GET["id"];
+$existing_money = $conn->query("SELECT miqdor FROM qarzdorlar WHERE id = $id");
+$existing_money = $existing_money->fetch_assoc()["miqdor"];
+
+if (array_key_exists("miqdor", $_POST) && $existing_money >= $_POST["miqdor"]) {
+ $miqdor = (int) $existing_money - $_POST["miqdor"];
+ $sql = "UPDATE qarzdorlar SET miqdor = $miqdor WHERE id = $id";
+ $result = $conn->query($sql);
+
+ if ($result === TRUE) {
+ header("Location: index.php");
+ } else {
+ echo "Error: " . $sql . "<br>" . $conn->error;
+ }
+} elseif (array_key_exists("miqdor", $_POST) && $existing_money <= $_POST["miqdor"]) {
+ header("Location: index.php");
+}
+
+?>
+
+</body>
+</html>
|