Sunday, 29 September 2013

MySQL database unrecognize chinese characters extracted from Excel file (xls)

MySQL database unrecognize chinese characters extracted from Excel file (xls)

I try to extract data (Chinese Charaters) from excel(.xls), but when
inserted, the database does not recognize the characters (appear blank and
symbols). Please help me to solve the problems.
<html>
<body>
<form action="upload_file_xls.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" id="file" /><br/>
<input type="submit" name="insert" value="Upload"/>
</form>
</body>
<?php
if(isset($_POST['insert'])){
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] ;
}
else{
include 'excel/reader.php';
$excel = new Spreadsheet_Excel_Reader();
$file = $_FILES['file']['tmp_name'];
$excel->read($file);
$x=1;
while($x<=$excel->sheets[0]['numRows']) {
$number = isset($excel->sheets[0]['cells'][$x][1]) ?
$excel->sheets[0]['cells'][$x][1] : '';
$province = isset($excel->sheets[0]['cells'][$x][2]) ?
$excel->sheets[0]['cells'][$x][2] : '';
$city = isset($excel->sheets[0]['cells'][$x][3]) ?
$excel->sheets[0]['cells'][$x][3] : '';
$alphabet = isset($excel->sheets[0]['cells'][$x][4]) ?
$excel->sheets[0]['cells'][$x][4] : '';
$link = mysql_connect('localhost', 'root', '');
mysql_set_charset('utf8',$link);
$db_selected = mysql_select_db('sugoroku01', $link);
if (!$db_selected) { die ('Database access error : ' .
mysql_error());}
$query = "INSERT INTO `province_city_tbl`(`province`,
`city`, `alphabet`)
VALUES ('".$province."', '".$city."',
'".$alphabet."') ";
mysql_query($query) or die('Error, Feedback insert
into database failed');
$x++;
}
}
}
?>
</html>

No comments:

Post a Comment