469,618 Members | 2,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,618 developers. It's quick & easy.

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

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])."',";
}
}

Jun 27 '08 #1
2 3309
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.
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.
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.
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.
Jun 27 '08 #2
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);
}
}
}
}
}
}
}
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ralph Freshour | last post: by
5 posts views Thread by Matthew Shaw | last post: by
11 posts views Thread by bissatch | last post: by
10 posts views Thread by John Smith | last post: by
3 posts views Thread by jatin299 | last post: by
2 posts views Thread by =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.