无法使用php将CSV文件中的多行上传到mysql数据库

时间:2017-01-11 07:16:39

标签: php mysql csv

我有以下CSV文件,没有文字管理器中的任何标题

54000,Khalid Plaza,Sunrise Towers,Airsure Premium,500
54001,Genie  Villa,Dubai Land,Airsure Standard,478
435678,Vox Plaza,Sunset Towers,Airsure Premium,500
22332,imax Plaza,Moonrise Towers,Airsure Premium,500

我尝试使用以下php代码上传此内容

if($_FILES["file"]["size"] > 0)
         {
            $file = fopen($filename, "r");
            while (($getData = fgetcsv($file)) !== FALSE)
             {
                $sql = "INSERT into jobtktdesc (jobtktnum,custname,sitename,typecont,idcontract) 
                   values ('".$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."')";
                   $result = mysqli_query($conn, $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(\"Submitted CSV File.\");
                        window.location = \"index.php\"
                    </script>";
                }
             }

             fclose($file); 
         }

但是我只能上传第一行。所有其他行都被跳过。

此致

0 个答案:

没有答案