-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput-snippet-admin.php
54 lines (47 loc) · 1.27 KB
/
input-snippet-admin.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
<?php
session_start();
include 'database/connect.php';
include 'functions.php';
include 'langCheck.php';
protectAdmin();
$title = $_POST['name'];
$desc = $_POST['description'];
$syntax = $_POST['syntax'];
$snippet = $_POST['snippet'];
$tagsArray = $_POST['tags'];
$tagsArray = json_decode($tagsArray);
$snippetId = $_POST['id'];
if( empty($title) ) {
echo $lang['emptyTitle'];
exit();
}
if( empty($snippet) ) {
echo $lang['emptySnippet'];
exit();
}
if( empty($tagsArray) ) {
echo $lang['emptyTag'];
exit();
}
if( empty($syntax) ) {
$syntax = 'none';
}
$stmt = $con->prepare("UPDATE snippets SET title = ?, description = ?, syntax = ?, snippet = ? WHERE id = ?");
$stmt->bind_param("ssss", $title, $desc, $syntax, $snippet, $snippetId);
$stmt->execute();
$stmt->close();
$query = $con->prepare("SELECT user_id FROM snippets WHERE id = ?");
$query->bind_param("s", $snippetId);
$query->execute();
$query->bind_result($user_id);
$query->fetch();
$query->close();
$w = $con->query("DELETE FROM tags_snippets WHERE snippets_id = '$snippetId'");
$q = $con->prepare("INSERT INTO tags_snippets VALUES('', ?, ?, ?)");
foreach( $tagsArray as $tag ) {
$q->bind_param("sss", $snippetId, $tag, $user_id);
$q->execute();
}
$q->close();
echo 'ok';
?>