-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.php
73 lines (66 loc) · 2.2 KB
/
insert.php
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
<!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
/**
* @author Bob S. <[email protected]>
* @copyright Copyright (c) 2022, Bob S.
* @license MIT
*/
require "db.inc.php";
$name = $_POST['hname'] ?? false;
$href = $_POST['href'] ?? false;
$private = $_POST['private'] ?? "false";
$desc = $_POST['desc'] ?? "";
$cat = $_POST['cat'] ?? 0;
if ($name === false || $href === false) {
try {
$sql = "SELECT id, category FROM cats";
$query = $pdo->query($sql);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
<form method="POST">
<label for="private">Mark as private</label>
<input type="checkbox" name="private" id="private" value="true" checked="checked" />
<select id="cat" name="cat">
<?php
foreach($query as $q) {
echo "<option value=\"{$q['id']}\">{$q['category']}</option>";
}
?>
</select>
<label for="name">Enter Name of Link</label>
<input type="text" name="hname" id="hname" maxlength="40"/>
<label for="href">Hyperlink</label>
<input type="text" name="href" id="href" maxlength="255" placeholder="https://" />
<label for="desc">Description</label>
<input type="text" name="desc" id="desc" maxlength="255" />
<input type="submit" />
</form>
<?php
} else {
try {
$sql = "INSERT INTO links (link_name, link_href, private, description, cat_id) VALUES (:name, :href, :private, :desc, :cat)";
$pdostmt = $pdo->prepare($sql);
if (! $pdostmt === false) {
$pdostmt->execute(["name"=>$name, "href"=>$href, "private"=>$private, "desc"=>$desc, "cat"=>$cat]);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
$_SESSION['last'] = false;
echo "<a href=\"index.php".bust()."\">Back to Home Page</a>";
}
?>
</body>
</html>