-
Notifications
You must be signed in to change notification settings - Fork 0
/
commentremedy.php
39 lines (32 loc) · 1.03 KB
/
commentremedy.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
<?php
session_start();
include 'connection.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$product_id = $_POST['product_id'];
$username = $_POST['username'];
$comment = test_input($_POST["comment"]);
if($username == ""){
echo "please login first";
}elseif($comment == ""){
echo "comment box empty";
}else{
$query = "INSERT INTO comments (product_id, username, comment_text, comment_date) VALUES ('$product_id', '$username', '$comment', NOW())";
if (mysqli_query($conn, $query)) {
// Comment added successfully
echo "comment added successfully";
// header("Location: your_product_page.php?id=$product_id"); // Redirect back to the product page
} else {
// Handle the error
echo "not sent remove all apostrophes";
// echo "Error: " . mysqli_error($conn);
}
mysqli_close($conn);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>