-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_cat.php
More file actions
79 lines (73 loc) · 1.99 KB
/
Copy pathedit_cat.php
File metadata and controls
79 lines (73 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="language" content="english">
<title>Home Page</title>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<?php
require "db.inc.php";
/**
* @author Bob S. <Tips@TechnoWizardBob.com>
* @copyright Copyright (c) 2022, Bob S.
* @license MIT
*/
if (! $loggedin) {
echo "Please log in!";
exit;
}
$id = (int) $_GET['id'] ?? 0;
$cat = $_POST['cat'] ?? false;
$delete = $_POST['delete'] ?? "false";
if ($cat === false || $id == 0) {
try {
$sql = "SELECT category FROM cats WHERE id=:id LIMIT 1";
$pdostmt = $pdo->prepare($sql);
if (! $pdostmt === false) {
$pdostmt->execute(["id"=>$id]);
$row = $pdostmt->fetch(PDO::FETCH_ASSOC);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
<form method="POST">
<label for="cat">Category</label>
<input type="text" name="cat" id="cat" value="<?= $row['category'] ?>" maxlength="255"/>
<br/><br/>
<input type="submit" />
</form>
<?php
} else {
$_SESSION['cat'] = false;
$_SESSION['last_modified_time'] = time();
if ($delete === "true") {
try {
$sql = "DELETE FROM cats WHERE id=:id LIMIT 1";
$pdostmt = $pdo->prepare($sql);
if (! $pdostmt === false) {
$pdostmt->execute(["id"=>$id]);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
} else {
try {
$sql = "UPDATE cats SET category=:cat WHERE id=:id LIMIT 1";
$pdostmt = $pdo->prepare($sql);
if (! $pdostmt === false) {
$pdostmt->execute(["cat"=>$cat, "id"=>$id]);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
}
echo "<a href=\"index.php".bust()."\">Back to Home Page</a>";
}
?>
</body>
</html>