<?php 
    include("../db.php");
    if($_POST){

        if(isset($_FILES["image"]["name"]) && !empty($_FILES["image"]["name"])){
    		$lfilename = basename($_FILES['image']['name']);
    		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
    		$lnewfile=md5(microtime()).".".$lext;
    		echo "$lnewfile";
    		if(move_uploaded_file($_FILES['image']['tmp_name'],"../uploads/alumni/".$lnewfile)){
    		    echo "hello";
    		    $_POST['image'] = $lnewfile;
    		}
    	}
    
   
 $id=$_GET['id'];
        $db->updateAry("alumni", $_POST, "where id=$id");
        
        header("Location: alumni");
    }
?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Dashboard</title>
    <?php include("meta.php"); ?>

</head>
<body> 
 
<?php include("header.php"); ?>

<?php include("sidebar.php"); 

if(isset($_GET['id'])){
    $id=$_GET['id'];
}

    $data = $db->getRow("select * from alumni where id=$id ");

?>

<div class="main">
    
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="content-div">
                    <h2>EDIT ALUMNI</h2>
                    
                    <form action="" method="post" enctype="multipart/form-data">
                        <div class="form-row row">
                            <div class="col-md-2"><label>name</label></div>
                            <div class="col-md-10"><input  name="name" value="<?php echo $data['name'];?>" style="width:100%;" >
                        </div>
                        </div>
                        <div class="form-row row" style="margin-top: 2%;">
                            <div class="col-md-2"><label>Profession</label></div>
                            <div class="col-md-10"><input  name="profession" value="<?php echo $data['profession'];?>" style="width:100%;"  >
                        </div>
                        </div>
                        <div class="form-row row" style="margin-top: 2%;">
                            <div class="col-md-2"><label>Image</label></div>
                            <div class="col-md-10"><input type="file" name="image" class="form-control" />
                                <?php if($data["image"]!=""){ ?>
                                    <img src="../uploads/alumni/<?php echo $data["image"]; ?>" style="width: 250px;">
                                <?php } ?>
                            </div>
                        </div>
                       <br>
                        <div class="form-row form-check text-center"><input type="submit" class="btn btn-primary" value="Save Changes"></div>
                    </form>
                    
                </div>

            </div>   
        </div>
    </div>
    
</div>
     
</body>
</html> 
