<link rel="stylesheet" href="../css/bootstrap.min.css" />
<?php include '../projects/project_menu.php' /** calling of header(to make it uniform in all template file) **/?>
<div class="container home">
		<h3> Update Project </h3>
		
		<?php
			include '../connection.php'; /** calling of connection.php that has the connection code **/
			
			$ID = $_GET['project_id']; /** get the student ID **/
			
			if( isset( $_POST['update'] ) ): /** A trigger that execute after clicking the submit 	button **/
				
				/*** Putting all the data from text into variables **/
				
							$title = $_POST['title']; 
				$details = $_POST['details'];
				$image = $_FILES['new_image']['name'];
				if($image != ''){
				$flag = true;
				}
				
				if($flag){
				$temp = explode(".",$_FILES["new_image"]["name"]);
echo $temp;
				$t=time();
				$newfilename = $t . '.' .end($temp);

$target_path = '../projects/project_img/';

$target_path = $target_path . $newfilename; 

if(move_uploaded_file($_FILES['new_image']['tmp_name'], $target_path )) {
} else{
    echo "There was an error uploading the file, please try again!";
}
				
			
				
				mysql_query("UPDATE project SET project_title = '$title', project_detail = '$details', project_image = '$newfilename'  WHERE project_id = '$ID'") 
							or die(mysql_error()); /*** execute the insert sql code **/
				}else{
				mysql_query("UPDATE project SET project_title = '$title', project_detail = '$details'  WHERE project_id = '$ID'") 
							or die(mysql_error()); /*** execute the insert sql code **/
				
				}			
				echo "<div class='alert alert-info'> Successfully Updated. </div>"; /** success message **/
			
			endif;
			
			
			$result = mysql_query("SELECT * FROM project WHERE project_id='$ID'");
			
			$data = mysql_fetch_object( $result ); 
			
		?>
		
		
		

		<form enctype="multipart/form-data"  action="" method="POST" >
			<label> Title: </label>
				<input type="text" value="<?php echo $data->project_title ?>" class="input-medium" name="title" style="width:525px;"/>
			<label> Details: </label>
				<textarea class="span7" name="details"><?php echo $data->project_detail ?></textarea>
			<label>Image: </label> 
			<img src="../projects/project_img/<?php echo $data->project_image?>" style="padding:5px"  width="150px"/>
			<label>Change Image: </label> 
			<input type="file" name="new_image" />
			<br><br>
				<input type="submit" name="update" value="Update" class="btn btn-info" />
			
		</form>				
	</div>	
</div>
</body>
</html>
