gpt4 book ai didi

php - mysqli_query 返回 false,因为值包含空格字符

转载 作者:行者123 更新时间:2023-11-29 21:48:51 24 4
gpt4 key购买 nike

我正在从 Excel 工作表插入数据,但收到错误,并且看起来它正在损坏,因为该值之间包含空格字符。据我记得 VARCHAR(200)

中允许使用空格字符

这是我正在使用的代码

//CREATE SQL QUERY FOR INSERTING DATA IN DATABASE
$sql = "INSERT INTO ".$month."_".$year."(";
foreach($sheetData[1] as $columnName){
$sql .= preg_replace('#[ ]#', '_',$columnName). ",";
}
$sql = rtrim($sql, ',');//REMOVES COMMA FROM END OF THE STRING
$sql .= ")";
//
$sql .= " VALUES((";
for($i=2;$i < count($sheetData);$i++){
foreach($sheetData[$i] as $columnName){
$sql .= $columnName.",";
}
$sql = rtrim($sql,',');//
$sql .= "),";
}
$sql = rtrim($sql,',');//
$sql .= ")";
echo $sql;
$query = mysqli_query($conn,$sql) or die(mysqli_error($conn));

循环后,这就是我的 SQL QUERY 的外观

INSERT INTO December_2015(S_No,Zone,State,City2,VM_Town,Distibutor_Code,Distributor_Name,Dealer_Code,Dealer_Name,Category,Address,Location,Contact,Mobile_No,Visit_1,Visit_2,Visit_3,Visit_4,Visit_5,Visit_6) VALUES( (1,South,Telanagana,Hyderabad,Y,1006704,Sai Santhoshi Enterprises,TG000999,Sree Laxmi Mobiles,A,F4,anthem Arcade,gujarathi Galli,koti ,Koti,Rajesh,8790575680,7-Nov,18-Nov,28-Nov))

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Santhoshi Enterprises,TG000999,Sree Laxmi Mobiles,A,F4,anthem Arcade,gujarathi G' at line 1

它在'Santhoshi Enterprises ...'附近显示,之前有一个空格字符

最佳答案

“VALUES”后面有两个“(”,而不是一个

关于php - mysqli_query 返回 false,因为值包含空格字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33860484/

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