gpt4 book ai didi

php - 在 mysql 中上传 CSV 文件时出现问题

转载 作者:行者123 更新时间:2023-11-29 20:12:08 25 4
gpt4 key购买 nike

在 mysql 中上传 csv 文件时出现此错误

Column count doesn't match value count at row 1

我的查询是:

if(isset($_POST['submit']))
{

$file=$_FILES['file']['tmp_name'];
$handle=fopen($file,"r");

while(($r=fgetcsv($handle,"500",",")) !==FALSE)
{

$sql="insert into `couponss` (promoid,offerid,offername,type,code,title,description,category,offerpage,dateadded,expiry,exclusive,featured) values('" . implode("','",$r)."')";

$result=mysqli_query($con,$sql) or die(mysqli_error($con));

//echo implode("','",$r);
}
}
else
{
echo "NO DIRECT SCRIPT ALLOWED";
}

这就是我的 csv 文件的样子

P43183','1126','Giftease.com CPS - India','Coupon','GIFTICICI20','Get 20% Off on orders above INR 1200*','TnC: The offers are valid on all eligible orders placed between 1st April 2015 to 31st March 2017 The offers are available on all items ordered on www.giftease.com excluding gift cards/vouchers, select watches & gift wrapping charges. Offer limited to usage of the code to 3 orders per customer Eligible orders: the order value of a single order must be equal or higher than Rs. 1200 or Rs.4000 excluding any items belonging to the excluded categories mentioned above Coupon code \"GIFTICICI20\"" or \""GEICICI1000\"" must be applied in the shopping cart',' prior to payment for eligible orders',' in orders to avail the offer Eligible orders must be paid for using ICICI Bank credit card',' debit card or netbanking only. The offers cannot be combined with any other offer available on www.giftease.com from time to time. All order are subject to the terms of use of www.giftease.com published at http://www.giftease.com/terms-of-use. This offer may be withdrawn or modified at any time at the discretion of Giftease or ICICI Bank."','Gifts & Flowers','http://tracking.vcommission.com/aff_c?offer_id=1126&aff_id=51664&url=http%3A%2F%2Fwww.giftease.com%2F%3Futm_source%3Dvcommission%26utm_medium%3Dbanner_emailer%26utm_campaign','Sep 16, 2016','Mar 31, 2017','0','0',

这只是第一行。我的 csv 文件中有大约 500 行这样的行

如果我在执行之前打印查询,它会完美地显示数据

执行的查询

insert into `couponss` (promoid,
offerid,
offername,
type,
code,
title,
description,
category,
offerpage,
dateadded,
expiry,
exclusive,
featured)
values('P43183',
'1126',
'Giftease.com CPS - India',
'Coupon',
'GIFTICICI20',
'Get 20% Off on orders above INR 1200*',
'TnC: The offers are valid on all eligible orders placed between 1st April 2015 to 31st March 2017 The offers are available on all items ordered on www.giftease.com excluding gift cards/vouchers, select watches & gift wrapping charges. Offer limited to usage of the code to 3 orders per customer Eligible orders: the order value of a single order must be equal or higher than Rs. 1200 or Rs.4000 excluding any items belonging to the excluded categories mentioned above Coupon code \"GIFTICICI20\"" or \""GEICICI1000\"" must be applied in the shopping cart',
' prior to payment for eligible orders',
' in orders to avail the offer Eligible orders must be paid for using ICICI Bank credit card',
' debit card or netbanking only. The offers cannot be combined with any other offer available on www.giftease.com from time to time. All order are subject to the terms of use of www.giftease.com published at http://www.giftease.com/terms-of-use. This offer may be withdrawn or modified at any time at the discretion of Giftease or ICICI Bank."',
'Gifts & Flowers',
'http://tracking.vcommission.com/aff_c?offer_id=1126&aff_id=51664&url=http%3A%2F%2Fwww.giftease.com%2F%3Futm_source%3Dvcommission%26utm_medium%3Dbanner_emailer%26utm_campaign',
'Sep 16, 2016',
'Mar 31, 2017',
'0',
'0')

最佳答案

这是因为你的mysql查询中只有13个列名和20多个列数据值。

还要确保在 mysql 中插入单元格值时使用``而不是''。

还要确保在 mysql 中插入单元格值时使用 mysqli_real_escape_string。

关于php - 在 mysql 中上传 CSV 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40018109/

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