我创建了一个组件 Joomla,现在我希望可以选择导入组件的数据。我浏览了一个教程,但导入功能不起作用。有人可以看看你是否可以帮我看看为什么它不起作用,谢谢?
问题:当我选择 csv 文件并单击上传时,它会转到一个空白页面并且未加载数据。
//这是上传文件的表单功能
<form enctype="multipart/form-data" action="components/com_account_manager/importCSV.php" method="POST">
<p>Choose a file to upload : <input name="file" type="file" /></p>
<p><input type="submit" value="Upload File" /></p>
</form>
//这是导入的php代码
<?php
$conn = mysql_connec("localhost","root","root") or die(mysql_error());
mysql_select_db("test",$conn);
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,"r");
while(($fileop = fgetcsv($handle,1000,",")) !== false)
{
$id = $fileop[0];
$asset_id = $fileop[1];
$ordering = $fileop[2];
$date = $fileop[3];
$username = $fileop[4];
$efile_transactions = $fileop[5];
$state_transactions = $fileop[6];
$bank_products = $fileop[7];
$first_overwitholding = $fileop[8];
$second_overwitholding = $fileop[9];
$balance_owed = $fileop[10];
$sql = mysql_query("INSERT INTO account_manager(
id,
asset_id,
odering,
date,
username,
efile_transactions,
state_transactions,
bank_products,
first_overwitholding,
second_overwitholding,
balance_owed
)
VALUES(
'$id',
'$asset_id',
'$ordering',
'$date',
'$username',
'$efile_transactions',
'$state_transactions',
'$bank_products',
'$first_overwitholding',
'$second_overwitholding',
'$balance_owed')");
}
if($sql)
{
echo 'CSV file successfully imported.';
}
}
?>