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

无法使用php将CSV文件中的多行上载到mysql数据库,php,mysql,csv,Php,Mysql,Csv,我有下面的CSV文件,没有任何标题,就像在text wrangler中一样 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 我正

我有下面的CSV文件,没有任何标题,就像在text wrangler中一样

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); 
         }
if($\u文件[“文件”][“大小”]>0)
{
$file=fopen($filename,“r”);
while(($getData=fgetcsv($file))!==FALSE)
{
$sql=“插入到jobtktdesc(jobtktnum、custname、sitename、typecont、idcontract)
值(“$getData[0]。”、“$getData[1]。”、“$getData[2]。”、“$getData[3]。”、“$getData[4]。”)”);
$result=mysqli\u查询($conn,$sql);
如果(!isset($result))
{
回声“
警报(\“无效文件:请上载CSV文件。\”;
window.location=\“index.php\”
";       
}
否则{
回声“
警报(\“提交的CSV文件。\”);
window.location=\“index.php\”
";
}
}
fclose($文件);
}
然而,我只能上传第一行。跳过所有其他行


关于,

我查看了上面的帖子,发现以下错误:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,了解在第1行“Plaza,Sunrise Towers,Airsure Premium,500 54001,精灵别墅,迪拜土地,Airsure S”附近使用的正确语法;新代码是while($line=fgets($file))!==FALSE){$values.=“($line),”;$values=substr($values,0,strlen($values)-1);$conn->query($sql_前缀.$values)或die($conn->error);}请尝试读取该注释。你能?请编辑这个问题。我看了上面的帖子,得到了以下错误:你的SQL语法有错误;查看与MySQL服务器版本对应的手册,了解在第1行“Plaza,Sunrise Towers,Airsure Premium,500 54001,精灵别墅,迪拜土地,Airsure S”附近使用的正确语法;新代码是while($line=fgets($file))!==FALSE){$values.=“($line),”;$values=substr($values,0,strlen($values)-1);$conn->query($sql_前缀.$values)或die($conn->error);}请尝试读取该注释。你能?请编辑这个问题。