Implemented counter
This commit is contained in:
13
api.php
13
api.php
@@ -82,6 +82,19 @@
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!in_array("counter", $tables)) {
|
||||||
|
query("CREATE TABLE `counter` (
|
||||||
|
`value` int NOT NULL,
|
||||||
|
PRIMARY KEY (`value`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
|
||||||
|
}
|
||||||
|
|
||||||
|
query("SELECT COUNT(value) AS count FROM counter;", function($row) {
|
||||||
|
if($row["count"] <= 0) {
|
||||||
|
query("INSERT INTO counter(value) VALUES (0);");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if(isset($_GET["cmd"])) {
|
if(isset($_GET["cmd"])) {
|
||||||
$cmd = $_GET['cmd'];
|
$cmd = $_GET['cmd'];
|
||||||
|
|
||||||
|
32
counter.php
Normal file
32
counter.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
include "api.php";
|
||||||
|
|
||||||
|
if(isset($_GET["increment"])) {
|
||||||
|
query("UPDATE counter SET value = value + 1;");
|
||||||
|
header("Location: /counter.php");
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Vkládání otázek</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Počítadlo</h1>
|
||||||
|
<h2>
|
||||||
|
Je tu
|
||||||
|
<?php
|
||||||
|
query("SELECT * FROM counter", function($row) {
|
||||||
|
echo($row["value"]);
|
||||||
|
})
|
||||||
|
?>
|
||||||
|
lidí!
|
||||||
|
</h2>
|
||||||
|
<form action="/counter.php" method="get">
|
||||||
|
<input type="hidden" name="increment" value="dick">
|
||||||
|
<input type="submit" value="Přišel další!">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Reference in New Issue
Block a user