generated from ToddSproull-WUSTL/V1-CSE330-Group-Template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
comment-add.php
31 lines (26 loc) · 921 Bytes
/
comment-add.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
<?php require 'database.php';
session_start();?>
<a href="comment-view.php">Back to comments</a>
<h3>Add Comment</h3>
<form action="comment-add.php" method="POST">
<label for="comment">New comment: </label>
<input type="text" id="comment" name="comment" placeholder="New comment here" Required>
<button type="submit" name="submit">Submit</button>
</form>
<?php
if(isset($_POST['comment'])) {
$mysqli = connectdb();
$newcomment = $_POST['comment'];
$sql = "INSERT INTO comments(commentstext, comuserid) VALUES(?, ?)";
$stmt = $mysqli -> prepare($sql);
if(!$stmt){
printf("Query Prep Failed: %s\n", $mysqli->error);
exit;
} else {
echo "Query successful!";
$stmt->bind_param('ss', $newcomment, $_SESSION['username']);
$stmt->execute();
$stmt->close();
}
}
?>