<?php

include "db-con.php";

if (isset($_POST['submit'])){
 
    // Allowed mime types
    $fileMimes = array(
        'text/x-comma-separated-values',
        'text/comma-separated-values',
        //'application/octet-stream',
       // 'application/vnd.ms-excel',
        'application/x-csv',
        'text/x-csv',
        'text/csv',
        'application/csv',
       // 'application/excel',
       // 'application/vnd.msexcel',
       // 'text/plain'
    );
 
    // Validate whether selected file is a CSV file
    if (!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'], $fileMimes))
    {
 
            // Open uploaded CSV file with read-only mode
            $csvFile = fopen($_FILES['file']['tmp_name'], 'r');
 
            // Skip the first line
            fgetcsv($csvFile);
 
            // Parse data from CSV file line by line
            while (($getData = fgetcsv($csvFile, 10000, ",")) !== FALSE)
            {
                // Get row data 
               // $id = $getData[0];
                $name = $getData[0];
                $email = $getData[1];
                $mobile = $getData[2];
                $participant_id = $getData[3];
                $event_id = $getData[4];
                $trainee_id = $getData[5];

 
                $q_update_data_1= "INSERT INTO participant (name, email, mobile, participant_id, event_id, trainee_id) VALUES ('" . $name . "', '" . $email . "', '" . $mobile . "', '" . $participant_id . "', '" . $event_id . "', '" . $trainee_id . "')";
                    
                    $result_2 = $con->query($q_update_data_1) or die("error");
                    
            }
 
            // Close opened CSV file
            fclose($csvFile); 
            header("Location: https://ais.org.in/digitalcertificate/dashboard_participation.php");
         
    }
    else
    {
        echo "Please select valid file";
    }
}

?>



