<?php
	
	session_start();

	include_once('../../../admin/articles/db/connection.php');

	$id = $_GET['id'];

	if(isset($_POST['comment'])){
		$blog_id = $_POST['blog_id'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$comments = $_POST['comments'];
		$rating = $_POST['rating'];
		$image = $_FILES['image']['name'];
		$target = "images/".basename($_FILES['image']['name']);

		$sql = "INSERT INTO comments (blog_id, name, email, comments, rating,image) VALUES ('$blog_id', '$name', '$email', '$comments', '$rating', '$image')";

		if (move_uploaded_file($_FILES['image']['tmp_name'], $target));

		//use for MySQLi OOP
		if($conn->query($sql)){
			$_SESSION['success'] = 'Comment Submitted';
		}
		///////////////

		//use for MySQLi Procedural
		// if(mysqli_query($conn, $sql)){
		// 	$_SESSION['success'] = 'Member added successfully';
		// }
		//////////////
		
		else{
			$_SESSION['error'] = 'Failed to submit comment';
		}
	}
	else{
		$_SESSION['error'] = 'Fill up form first';
	}

	header('location: ../index.php?id=$id;');
?>