插入表不工作?

时间:2015-08-24 02:04:41

标签: mysql sql-insert

我有这个代码,当我在我的localhost中运行时,它正在以它应该的方式工作。但是当我在实时数据库中执行它时,它只是插入第一个文件中的第一个数据。所有数据类型都相同。

<?php 

//connect to the database 
$connect = mysql_connect("localhost","root",""); 
mysql_select_db("pc2015",$connect); //select the table 

//get the csv file from directory
$dir = "UnzipFiles/";
$currentFile = glob($dir."*.csv");

foreach ( $currentFile as $filename) {
    $handle = fopen($filename,"r");
    $file = basename($filename);

//loop through the csv file and insert into database 
    do { 
        if ($data[0]) { 
            mysql_query("INSERT INTO pcoordinates (gps_id,lat,lng,time,pv,mn,by,ea,bn,cn,hsn,name) VALUES 
                ( 
                    '$file',
                    ".mysql_real_escape_string($data[0]).",
                    ".mysql_real_escape_string($data[1]).",
                    '".mysql_real_escape_string($data[2])."',
                    '".mysql_real_escape_string($data[3])."',
                    '".mysql_real_escape_string($data[4])."',
                    '".mysql_real_escape_string($data[5])."',
                    '".mysql_real_escape_string($data[6])."',
                    '".mysql_real_escape_string($data[7])."',
                    '".mysql_real_escape_string($data[8])."',
                    '".mysql_real_escape_string($data[9])."',
                    '".mysql_real_escape_string($data[10])."'
                ) 
            "); 
        } 
    } while ($data = fgetcsv($handle,1000,",","'")); 
    }
?>

此代码在我的localhost中运行,并再次运行良好。在我的实时数据库中,我只是更改连接代码。我的代码中缺少什么?谢谢

1 个答案:

答案 0 :(得分:0)

尝试这种方式,不需要使用(+)符号,看看(,)

抱歉,它是从我的java代码中复制的。

                + "'" + Txt_G_ID.getText() + "',"
                + "'" + Txt_G_Nam.getText() + "',"
                + "'" + 00 + "',"          //   ^........... 
                + "'" + 00 + "',"         
                + "'" + 00 + "',"
                + "'" + 00 + "',"            
                +"'"  + 00 +"',"