<?php
	//require_once 'conn.php';
//	
//	if(ISSET($_POST['update'])){
//		$user_id = $_POST['user_id'];
//		$firstname = $_POST['firstname'];
//		$lastname = $_POST['lastname'];
//		$address = $_POST['address'];
//		
//		mysqli_query($conn, "UPDATE `user` SET `firstname` = '$firstname', `lastname` = '$lastname', `address` = '$address' WHERE `user_id` = '$user_id'") or die(mysqli_error());
//
//		header("location: index.php");
//	}
	/*********************************************/
	
  // }
   	//include 'db_connection.php';
	require_once 'db_connection.php';
	$conn = OpenCon();
	//$con = mysqli_connect('localhost','u242028897_bhangar1',"MS1ragnahB");
 	//mysqli_select_db($con,"u242028897_bhangar1");
	/**************************************************************************************/
	if (mysqli_connect_errno()) 
	{
		echo "Unable to connect to MySQL! ". mysqli_connect_error();
	}
	if (isset($_POST['save'])) 
	{
		$target_dir = "school_pic/";
		$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;
		}
		
		/***********************************************************************************/
		//$query1="SELECT MAX(roundno) FROM round";
		$myID=$_POST['user_id'];
		$mytxtSubject=$_POST['txtSubject'];
		$myUploadDate=$_POST['dtpUploadDate'];
		$myfilename1=$_POST['txtOldFileName'];
		$myfilename2=$strfileName1;
		$location = $target_file;
		$myLocation="/home/u242028897/domains/bhangar1block.com/public_html/";
		$file1=$myLocation.$myfilename1;
		if(file_exists($file1)) 
		{
			unlink($file1);
		} 
		$query="UPDATE `school_info` set subject='$mytxtSubject',Upload_date='$myUploadDate',Location='$location',Filename='$myfilename2' WHERE sl_no='$myID'";
		$query_run=mysqli_query($conn,$query);
		header("location: sch_entry_modify.php");
}
?>