Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I was convert my excel file to CSV with Unicode (utf-8) but it can't insert to database.

newsendsms.php
--------------------------
PHP
<?php
									

										mysql_query("SET NAMES utf8");
										
										if(isset($_POST["Import"])){
												echo $filename = $_FILES["file"]["tmp_name"];
												if($_FILES["file"]["size"]>0){
													$file = fopen($filename, "r");
													
											
													//$sql_data = "SELECT * FROM tblnewusersendsms";
														while(($emapData = fgetcsv($file,10000, ",")) !==FALSE)
														{
															$emapData = mb_convert_encoding($emapData, "EUC-JP", "auto");
															mysql_query("SET NAMES utf8");
															$sql = "INSERT INTO tblnewusersendsms (ACC_NBR , TERMINAL_TYPE , CUST_NAME , CUST_TYPE , DEF_LANG_NAME , CREATED_DATE) VALUES ('$emapData[0]','$emapData[1]', '$emapData[2]', '$emapData[3]', '$emapData[4]', STR_TO_DATE('$emapData[5]','%m/%d/%Y'))";
															
															 
										mysql_query($sql);
																
															$res = $conn->query($sql);	
					}
				    fclose($file);
					echo '<div class="alert alert-success >
									<button type="button" class="close" data-dismiss="alert">×</button>
									
Posted
Updated 8-Feb-16 21:28pm
v4
Comments
Sergey Alexandrovich Kryukov 9-Feb-16 3:26am    
Don't write "What I have tried", tell us what have you tried.
—SA
Richard MacCutchan 9-Feb-16 4:01am    
And? What happens?
NightWizzard 9-Feb-16 13:30pm    
I think the line
$emapData = mb_convert_encoding($emapData, "EUC-JP", "auto");
is the problem. You pass $emapData as the first parameter which is an array, but the function expects a single string as first parameter! So the result will be undefined and can't be filled into the SQL query string.
Member 12315606 9-Feb-16 21:47pm    
This is my table in CSV File
-------------------------------------
NUMBER MOBILE NAME CUST_TYPE DEF_LANG_NAME DATE
189999154 MOBILE Srun 公众客户 English英语 2016/01/21
189999155 MOBILE Son 公众客户 English英语 2016/01/21
189988765 MOBILE Penn 集团客户 English英语 2016/01/20
189266676 MOBILE Thaing 集团客户 English英语 2016/01/20
189356767 MOBILE Luy 集团客户 English英语 2016/01/20
Member 12315606 9-Feb-16 21:07pm    
So how can we do? Please Help me?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900