Skip to content

Instantly share code, notes, and snippets.

@leewp14
Created April 19, 2018 00:26
Show Gist options
  • Save leewp14/9d09f092ce4b095617753c59b8c5e058 to your computer and use it in GitHub Desktop.
Save leewp14/9d09f092ce4b095617753c59b8c5e058 to your computer and use it in GitHub Desktop.
<?php
$session = "sk2017";
session_start($session);
include('../../../assets/config/connection.php');
$classLst = array("1T1", "1T2", "1T3", "1T4", "1T5", "1T6", "1T7", "1T8", "1T9", "1T10", "1T11", "1T12", "1T13", "1T14");
if(isset($_FILES['file'])&&$_FILES['file']['error']==0){
$file = $_FILES['file']['tmp_name'];
$fileCheck = $_FILES['file']['name'];
$ext = pathinfo($fileCheck, PATHINFO_EXTENSION);
if($ext !== 'csv') {
echo "Invalid file, please retry";
}else{
$fileOpen = fopen($file,'r');
while(!feof($fileOpen)){
$fileParse = fgetcsv($fileOpen,'0');
if(empty($fileParse[0])||empty($fileParse[1])||empty($fileParse[2])){
}else if(!in_array(strtoupper($fileParse[2]), $classLst)){
}else{
$query = "SELECT stdNum FROM std WHERE stdNum='".$fileParse[0]."'";
$get = mysqli_query($con,$query);
if($get){
if(mysqli_num_rows($get) == 0){
$fileParse[1] = mysqli_real_escape_string($con, $fileParse[1]);
$query0 = "INSERT INTO `std` (`stdNum`, `stdName`, `stdClass`) VALUES ('".strtoupper($fileParse[0])."', '".strtoupper($fileParse[1])."', '".strtoupper($fileParse[2])."');";
$query1 = "INSERT INTO `reg` (`regID`, `regDate`, `userID`, `stdNum`) VALUES ('', NOW(), '$_SESSION[userID]', '".strtoupper($fileParse[0])."');";
mysqli_query($con,$query0);
mysqli_query($con,$query1);
}else{
$query = "SELECT * FROM reg WHERE stdnum='".$fileParse[0]."'";
$get = mysqli_query($con,$query);
if($get){
if(mysqli_num_rows($get) == 0){
$query = "INSERT INTO `reg` (`regID`, `regDate`, `userID`, `stdNum`) VALUES ('', NOW(), '$_SESSION[userID]', '".strtoupper($fileParse[0])."');";
mysqli_query($con,$query);
};
}else{};
};
}else{};
};
};
fclose($fileOpen);
echo "Operation completed. Please check name list to ensure successful data entry. ";
}
}else{
echo "Invalid operation, please retry";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment