-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddcomment.php
34 lines (31 loc) · 1.01 KB
/
addcomment.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
<?php
include 'db.php';
if(isset($_POST["id"])){
$id = $_POST["id"];
$comment = strip_tags($_POST["comment"]);
// Check if the id exists in the notes table
$check_stmt = $conn->prepare("SELECT id FROM notes WHERE id = ?");
if ($check_stmt) {
$check_stmt->bind_param("i", $id);
$check_stmt->execute();
$check_stmt->store_result();
if ($check_stmt->num_rows > 0) {
// id exists, proceed to insert the comment
$stmt = $conn->prepare("INSERT INTO replys (note_id, reply) VALUES (?, ?)");
if ($stmt) {
$stmt->bind_param("is", $id, $comment);
$stmt->execute();
$stmt->close();
} else {
echo "Error preparing statement: " . $conn->error;
}
}
$check_stmt->close();
} else {
echo "Error preparing check statement: " . $conn->error;
}
header("location: view_note.php?id=$id");
}else{
header("location: index.php");
}
?>