gpt4 book ai didi

php - 请帮助,上传 csv 文件时出现错误

转载 作者:行者123 更新时间:2023-11-30 23:36:30 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
I have problem while uploading the csv file

如果特定月份的详细信息尚未存在,csv 文件将插入新值,如果特定月份的详细信息已存在于表中,则它将使用表中的新数据更新行csv 文件。

csv 文件的最后一行在工资单表的所有列中重复出现。我知道我的查询中有一些错误。但我不知道出了什么问题。谁能帮我解决这个问题?

 <?php
require_once '../config.php';

if(isset($_POST['upload']))
{
$fname = $_FILES['sel_file']['name'];
$month = $_POST['month'];
$chk_file = explode(".",$fname);

if(strtolower($chk_file[1]) == 'csv')
{
//$sel=mysql_query("select * from employee where month='$month'");
//$del=mysql_query("delete from employee where month='$month'");
$query1 = mysql_query("SELECT * FROM payslips where month='$month'");
$pay_num_rows = mysql_num_rows($query1);
$filename = $_FILES['sel_file']['tmp_name'];
$handle = fopen($filename,"r");
fgetcsv($handle,1000,",");
if($pay_num_rows > 1)
{
while(($data = fgetcsv($handle,1000,",")) != false)
{
$upd = "UPDATE payslips SET month='$data[9]',tot_work_days='$data[10]',lop_days='$data[11]',arrear_amt='$data[12]',leav e_encash='$data[13]' where month='$month'";
mysql_query($upd) or die(mysql_error());
}
fclose($handle);
echo "Successfully Imported";
}
if($pay_num_rows == 0)
{
while(($data = fgetcsv($handle,1000,",")) != false)
{
$sql = "INSERT into payslips(employee_code,employee_name,employee_address,emp_dateofjoin,emp_designation,emp_hq ,pf_num,esic_num,emp_state,month,tot_work_days,lop_days,arrear_amt,leave_encash) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[ 7]','$data[8]','$month','$data[10]','$data[11]','$data[12]','$data[13]')";
//$upd = "UPDATE employee SET month='$data[9]',tot_work_days='$data[10]',lop_days='$data[11]',arrear_amt='$data[12]',leav e_encash='$data[13]' where month='$month'";
mysql_query($sql) or die(mysql_error());
}
fclose($handle);
echo "Successfully Imported";

}
else
{
echo "Invalid File";
}
}
}

?>

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com