-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-snippet.php
45 lines (36 loc) · 1.13 KB
/
get-snippet.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
<?php
session_start();
include 'database/connect.php';
include 'functions.php';
protect();
$id = $_POST['id'];
$flag = $_POST['flag'];
$query = $con->prepare("SELECT user_id FROM users WHERE username = ?");
$query->bind_param("s", $_SESSION['user']);
$query->execute();
$query->bind_result($user_id);
$query->fetch();
$query->close();
if($flag === 'true') {
$query = $con->prepare("SELECT snippet FROM snippets WHERE id = ? AND user_id = ?");
$query->bind_param("ss", $id, $user_id);
$query->execute();
$query->bind_result($code);
$query->fetch();
$query->close();
echo htmlspecialchars($code, ENT_QUOTES, "UTF-8");
} else {
$query = $con->prepare("SELECT title, description, syntax, snippet FROM snippets WHERE id = ? AND user_id = ?");
$query->bind_param("ss", $id, $user_id);
$query->execute();
$query->bind_result($title, $description, $syntax, $snippet);
$query->fetch();
$query->close();
$array = array();
$array['title'] = $title;
$array['description'] = $description;
$array['syntax'] = $syntax;
$array['snippet'] = $snippet;
echo json_encode($array, JSON_HEX_QUOT | JSON_HEX_TAG);
}
?>