Connecting Tech Pros Worldwide Help | Site Map

uploading special characters from excel to mysql and php binary/Image

matech
Guest
 
Posts: n/a
#1: Jun 27 '08
I have a problem with uploading special characters from excel files to
mysql 5. It doesn't matter if I use UTF-8 or iso-8859-1 when uploading
the trademark ™ symbol. htmlspecialchars() or htmletities() doesn't
help? the database doesn't show the data in the field but replaces it
with the binary/Image information.

the following are examples of how I've tried loading the data along
with UTF-8 or iso-8859-1:


foreach ($SelectFields as $TempSelect) {
if($SelectedFieldValues[$TempSelect] == ''){
$strSQLQuery .= "'',";
} else {
$strSQLQuery .=
"'".htmlentities(addslashes($SelectedFieldValu es[$TempSelect]))."',";
}
}

or

foreach ($SelectFields as $TempSelect) {
if($SelectedFieldValues[$TempSelect] == ''){
$strSQLQuery .= "'',";
} else {
$strSQLQuery .=
"'".htmlentities($SelectedFieldValues[$TempSelect])."',";
}
}

or

foreach ($SelectFields as $TempSelect) {
if($SelectedFieldValues[$TempSelect] == ''){
$strSQLQuery .= "'',";
} else {
$strSQLQuery .=
"'".htmlspecialchars(addslashes($SelectedFieldValu es[$TempSelect]))."',";
}
}

or

foreach ($SelectFields as $TempSelect) {
if($SelectedFieldValues[$TempSelect] == ''){
$strSQLQuery .= "'',";
} else {
$strSQLQuery .=
"'".htmlspecialchars($SelectedFieldValues[$TempSelect])."',";
}
}

Captain Paralytic
Guest
 
Posts: n/a
#2: Jun 27 '08

re: uploading special characters from excel to mysql and php binary/Image


On 17 Jun, 15:47, matech <robert.mat...@hotmail.co.ukwrote:
I have read and re-read this post and I cannot manage to make it make
any sense.
Quote:
I have a problem with uploading special characters from excel files to
mysql 5.
mysql is an RDBMS. You do not upload special characters to it. You
insert values into fields.
Quote:
It doesn't matter if I use UTF-8 or iso-8859-1 when uploading
the trademark ™ symbol. htmlspecialchars() or htmletities() doesn't
help? the database doesn't show the data in the field but replaces it
with the binary/Image information.
What do you mean by this? If I have a VARCHAR field, it can only hold
text. I will not see an image there.
Quote:
the following are examples of how I've tried loading the data along
with UTF-8 or iso-8859-1:
>
foreach ($SelectFields as $TempSelect) {
* *if($SelectedFieldValues[$TempSelect] == ''){
* * * $strSQLQuery .= "'',";
* *} else {
* * *$strSQLQuery .=
"'".htmlentities(addslashes($SelectedFieldValu es[$TempSelect]))."',";
* *}
>
}
Please show us where $SelectFields comes from, what data gets into
$TempSelect, what the table schema is, which field of the table
$TempSelect will be loaded into, what the value is that is found in
the field.

In other words, give us something concrete to work with.
matech
Guest
 
Posts: n/a
#3: Jun 27 '08

re: uploading special characters from excel to mysql and php binary/Image


The following is the function used to upload the excel file.

function UploadProductTemp($arrayDetails) {
global $configTables;
extract($arryDetails);
$ArrayFieldName = $this->GetFieldName('product_temp');
foreach($ArrayFieldName as $key=>$values){
if($values['Field'] != 'productID') $SelectFields[$values['Field']]
= $values['Field'];
}
function GetExcelExtension($file){
$revfile=strrev($file); // Reverse the string for getting the
extension
$arr_t=explode(".",$revfile);
$file_type=$arr_t[0];
return strrev($file_type); // File Extension
}
$file_type=GetExcelExtension($FilePath);
if($file_type=='xls' || $file_type=='XLS') $supported=1;
else $supported=2;
if($supported>1){
echo "Sorry, File can't be uploaded, Please Upload only excel
file."; exit;
}else{
$Destination = $FilePath;
$Destination = 'upload/product.xls';
$obj=new product();
$objSupp=new supplier();
$data=new Spreadsheet_Excel_Reader();
$data->read($Destination);
for ($i = $startFrom+1; $i <= $data->sheets[0]['numRows']; $i++)
{
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
foreach ($SelectFields as $TempSelect) {
$sel = 's'.$TempSelect;
$Selected = $$sel;
if($j==$Selected){
$SelectedFieldValues[$TempSelect] =$data->sheets[0]
['cells'][$i][$j];
}
}
}
if(count($SelectedFieldValues) 0 && $i>$startFrom){
if($obj->isProductExists('product_temp',
$SelectedFieldValues['catalogNumber'])){
$strSQLQuery = "update bioscience_product set ";
foreach ($SelectFields as $TempSelect) {
$strSQLQuery .=
$TempSelect."='".htmlentities(addslashes($Selected FieldValues[$TempSelect]))."',";
}
$strSQLQuery = rtrim($strSQLQuery,",");
$strSQLQuery .= "where catalogNumber='".
$SelectedFieldValues['catalogNumber']."'";
}else{
if(($SelectedFieldValues['productName']!='') and
($SelectedFieldValues['catalogNumber']!='')) {
$strSQLQuery = "insert into product_temp(";
$strSQLQuery .= implode(",",$SelectFields);
$strSQLQuery .= ")values(";

foreach ($SelectFields as $TempSelect) {
if($SelectedFieldValues[$TempSelect] == ''){
$strSQLQuery .= "'',";
}else{
$strSQLQuery .=
"'".htmlentities(addslashes($SelectedFieldValu es[$TempSelect]))."',";
}
}
$strSQLQuery = rtrim($strSQLQuery,",");
$strSQLQuery .= ")";
$this->query($strSQLQuery, 0);
}
}
}
}
}
}
}
Closed Thread