-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommentAdd.php
More file actions
30 lines (23 loc) · 953 Bytes
/
Copy pathcommentAdd.php
File metadata and controls
30 lines (23 loc) · 953 Bytes
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
<?php
include('includes/config.php');
if(isset($_POST['submit']))
{
if ((!empty($_POST['name'])) && (!empty($_POST['email'])) && (!empty($_POST['content'])) &&(!empty($_POST['id']))) {
$newsId = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$content = $_POST['content'];
$query = "INSERT INTO comments(newsId,name,email,content,date) VALUES('$newsId','$name','$email','$content',NOW())";
$result = mysqli_query($con,$query);
if ($result) {
$query = "UPDATE news SET comments = comments + 1 WHERE id = $newsId";
$result = mysqli_query($con, $query);
echo "<script>alert('comment successfully added !');</script>";
}
else
echo "<script>alert('Something went wrong. Please try again.');</script>";
}
}
$id = $_POST['id'];
header('location:details.php?id='.$id);
?>