<?php
	session_start();
	include_once('../db/connection.php');

	if(isset($_POST['add'])){
		$name = $_POST['name'];
		$position = $_POST['position'];
		$testimonial = $_POST['testimonial'];
		$image = $_FILES['image']['name'];

		$target = "../images/".basename($_FILES['image']['name']);
		$sql = "INSERT INTO testimonials (name, position, testimonial, image) VALUES ('$name', '$position', '$testimonial', '$image')";

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

		//use for MySQLi OOP
		if($conn->query($sql)){
			$_SESSION['success'] = 'Testimonial added successfully';
		}
		
		else{
			$_SESSION['error'] = 'Something went wrong while adding testimonial';
		}
	}

	header('location: ../');
?>