
<?php
	//require_once 'conn.php';
	
	
	//include 'db_connection.php';
	require_once 'db_connection.php';
	$conn = OpenCon();
	//$conn = mysqli_connect("localhost","root","","dbupload");
	if (mysqli_connect_errno()) 
	{
		echo "Unable to connect to MySQL! ". mysqli_connect_error();
	}
	if (isset($_POST['save'])) 
	{
		$target_dir = "school_pic/";
		//echo "tets" . $target_dir . "<br>";
		$target_file = $target_dir . date("dmYhis") . basename($_FILES["file"]["name"]);
		$strfileName1=basename($_FILES["file"]["name"]);
		$uploadOk = 1;
		$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
 
		if($imageFileType != "jpg" || $imageFileType != "png" || $imageFileType != "jpeg" || $imageFileType != "gif" ) 
		{
			if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) 
			{
				$files = date("dmYhis") . basename($_FILES["file"]["name"]);
			}
			else
			{
				echo "Error Uploading File";
				exit;
			}
		}
		else
		{
			echo "File Not Supported";
			exit;
		}
		$strSubject = $_POST['txtSubject'];
		$dateUploaddate = $_POST['dtpUploadDate'];
		echo $dateUploaddate;
		$location = "school_pic/" . $files;
		echo $location;
		//$strUploadby = $_POST['txtUploadby'];
		//$strcontactNo = $_POST['txtContact'];
		$strfileName=$strfileName1;
		
		
		$sqli = "INSERT INTO `school_info` (`Subject`, `Upload_date`,`Location` , `Filename` ) VALUES 			      ('{$strSubject}','{$dateUploaddate}','{$location}','{$strfileName}')";
		//echo $sqli;
		$result = mysqli_query($conn,$sqli);
		//echo $result;
		if ($result)
		{
			echo "File has been uploaded";
			header("location: sch_entry_modify.php");
		};
	}
	
	//header("location: sch_entry_modify.php");
	
	
	//if(ISSET($_POST['save']))
//	{
//		$firstname = $_POST['firstname'];
//		$lastname = $_POST['lastname'];
//		$address = $_POST['address'];
//		
//		mysqli_query($conn, "INSERT INTO `user` VALUES('', '$firstname', '$lastname', '$address')") or die(mysqli_error());
//		
//		header("location: index.php");
//	}
?>

