我是php的新手,我已经使用html中的输入文本框成功将数据加载到sql中,但是我无法通过读取csv文件将其加载到数据库中,并且我正在为fopen函数获取解析错误。请帮忙
upload.php的
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ib";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else
$file=$_FILES["file"]["tmp_name"];
echo $file
fopen($file, 'r');
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
$sql = "INSERT into ib(atmid,location,zone,cash,fault) values('.$emapData[0]','.$emapData[1]','.$emapData[2]','.$emapData[3]','.$emapData[4])";
$conn->query($sql);
}
fclose($test);
echo "CSV File has been successfully Imported.";
?>
答案 0 :(得分:2)
您$sql
有引号问题,下面是更新的问题:
$sql = "INSERT into ib(atmid,location,zone,cash,fault) values('".$emapData[0] ."','".$emapData[1] ."','" . $emapData[2] . "','".$emapData[3] . "','".$emapData[4] . "')";