0) { $ret = 'You did not Select the result Datafile, Browse and Select it before clicking Upload Button' ; //echo "Error: " . $_FILES["images"]["error"] ; } else { //define variables $adyear = trim($_POST['ayear']); $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); $c = 0; while(($filesop = fgetcsv($handle, 1000, ",")) !== false) { $names = $filesop[0]; $regno = $filesop[1]; //check for duplicate $chk = $DBcon->prepare("select * from $tbl where regno = '$regno'") ; $chk->execute() ; if($chk->rowcount() > 0) { $erron[] = $regno ; } else { $sql = $DBcon->prepare("insert into $tbl (studentname,regno,name,avatar,admyear,stclass,gender) values ('$names','$regno' , 'name','avatar', '$adyear', 'class', 'gender')"); if($sql->execute()) $ok = 'yes' ; else $ok = 'no'; $c = $c + 1; } } if($ok = 'yes'){ //echo "You database has imported successfully. You have inserted ". $c ." recoreds"; $message[] = " Names Uploaded Succesfully ". $c ." recoreds"; }else{ $message [] = "Sorry! There is some problem."; } } } ?>