-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.php
More file actions
49 lines (43 loc) · 1.46 KB
/
Copy pathcomment.php
File metadata and controls
49 lines (43 loc) · 1.46 KB
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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include ('./config/createConnection.php');
session_start();
$imageid = $_POST['imageid'];
$comment = htmlspecialchars($_POST["comment"]);
$userid = $_SESSION["id"];
$username = $_SESSION["username"];
$comment_len = strlen($comment);
if($comment_len > 100){
header("location: gallery.php?error=1");
} else {
try {
$sql = "INSERT INTO comments (userid, username, imageid, text)
VALUES ('".$userid."', '".$username."', '".$imageid."', '".$comment."')";
$stmt = $conn->prepare($sql);
if ($stmt->execute()){
$sql = "SELECT user.userid, user.username, user.notifications, user.email, images.imageid, images.source FROM user, images WHERE user.userid = images.userid";
$stmt = $conn->prepare($sql);
}else{
echo "ERROR";
}
if ($stmt->execute() && $stmt->rowCount() > 0){
$row = $stmt->fetch(PDO::FETCH_ASSOC);
//echo "<pre>" . print_r($row) . "<pre>";
if($row['notifications'] == 1){
mail($row['email'], $_SESSION['username']." commented on your picture",
"Your picture posted on Camagru was commented on by ".$_SESSION['username']." - ".$comment);
}
}
header("location: gallery.php?success=1");
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
header("location: gallery.php?success=0&injection=0");
}
$conn = null;
}
//echo "FAIL"
?>