Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once ("config.php");
- $conn = new mysqli($servername, $username, $password, $dbname);
- if($conn->connect_error){
- die("Connection failed: " . $conn->connect_error);
- }
- if(isset($_POST["Import"])){
- $filename=$_FILES["file"]["tmp_name"];
- if($_FILES["file"]["size"] > 0)
- {
- $file = fopen($filename, "r");
- while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
- {
- $sql = "INSERT INTO `users` (`id`, `meno`, `email`, `heslo`, `team`, `role`, `accept`, `points`) VALUES
- ('$getData[0]','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."','".$getData[5]."','".$getData[6]."','".$getData[7]."')";
- //result = mysqli_query($con, $sql);
- echo $sql;
- $result = $conn->query($sql);
- if(!isset($result))
- {
- echo "<script type=\"text/javascript\">
- alert(\"Invalid File:Please Upload CSV File.\");
- window.location = \"index.php\"
- </script>";
- }
- else {
- echo "<script type=\"text/javascript\">
- alert(\"CSV File has been successfully Imported.\");
- window.location = \"index.php\"
- </script>";
- }
- }
- fclose($file);
- //var_dump($getData);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment