我有这个脚本允许我将 csv 文件内容插入 mysql,现在,我的问题是,我不知道为什么它将日期和手机号码的字段放在同一个地方。日期和手机号码都是数据库中的不同字段,都是 varchar 类型。
现在,这是代码:
if (isset($_POST['submit'])) {
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
echo "<h2>Displaying contents:</h2>";
readfile($_FILES['filename']['tmp_name']);
}
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$import="INSERT into imovo(date,time,location,rbpos_id,mobile_number) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
它不会正确上传数据。这是它上传数据的方式,并且数据不会全部进入数据库:
8/31/12,12:34:40,Tirane1,2345,662080090 8/32/2012,15:34:40 PM,Tirane2,2345,662080091 8/33/2012,18:34:40 PM,Tirane3,2345,662080092Import done
如果你看到,日期和手机号码一起去..