-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
76 lines (54 loc) · 1.95 KB
/
post.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
74
75
76
<?php
session_start();
include "templates/htmlheader.php";
include "config/db.php";
include "functions/systemfunctions.php";
checksignin();
$id = $_SESSION['id'];
if(isset($_POST['submit'])){
$title = $_POST['title'];
$content = $_POST['content'];
$userid = $id;
$tag = $_POST['tag'];
$sql = "INSERT INTO post(title, content, userid, tag) VALUES (?, ?, ?, ?)";
// Create a prepared statement
$stmt = mysqli_stmt_init($db);
// Prepare the statement
if(!mysqli_stmt_prepare($stmt, $sql)){
echo "SQL Statement Failed.";
return;
} else {
// Bind parameters to the placeholders
mysqli_stmt_bind_param($stmt, "ssii", $title, $content, $userid, $tag); // Run parameters inside database
mysqli_stmt_execute($stmt);
header("Location: index.php");
}
}
?>
<div class="col-md-8 offset-md-2">
<form action="post.php" method="post">
<h1>Add a post</h1>
<input type="number" name="userid" value="<?= $id ?>" hidden>
<label>Title</label>
<input type="text" name="title" class="form-control" autofocus required>
<label>Body</label>
<textarea name="content" id="editor1" cols="30" rows="50" required autofocus></textarea>
<label>Tag</label>
<select name="tag" class="form-control">
<option value=""></option>
<?php
// get tags as dropdown options
$gettags = "select * from tags";
$process4 = mysqli_query($db, $gettags);
foreach($process4 as $tag) { ?>
<option value="<?= $tag['id'] ?>"><?= $tag['tag'] ?></option>
<?php } ?>
</select>
<br>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
<script>
CKEDITOR.replace( 'editor1' );
</script>
<?php include "templates/footer.php" ?>