0

Hi all,

I have a problem with my php and mysql project.
I use an auctions software, named phpauction for my project.

I import into my database with utf8 encodingm and I can see the greek letters inside the fields.
The problem is that when i go to the site for the results, I get question marks instead of the greek characters.
I have searched a lot, and i found that there is a solution by adding mysql_query("SET NAMES utf8") after mysql_select_db.

Is that correct?
Also, i can not find the mysql_select_db in any of the files.

Thank you.

3
Contributors
13
Replies
14
Views
9 Years
Discussion Span
Last Post by Punkis448
0

Check what encoding you have set for your web page, If it is Latin 1 (ISO-8859-1) then the Greek characters will not be displayed.
You could check for without touching you code by browsing to your page and then (in Firefox 3) go to View -> Character Encoding and select UTF-8 since thats what it seems you are using, If the characters display correctly then you will just need add the following tag in the head section of all your HTML pages:-

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

So that all the browsers treat it by default as a UTF-8 encoded page

0

Hi Punkis,
character encoding mismatch can be a nightmare.
The database, tables and attributes all have charset and collation. Make sure it's set to UTF8 and utf8_general_ci (or utf8_your_language_code).

Then you need to make sure that you select a character set both when importing into and when reading from the database. You "SET CHARACTER SET utf8" or "SET NAMES utf8" - NAMES will set collation to default for given character set which may or may not be good for you (not if you used utf8_your_language_code).

Also, sometimes you think the data you import is in UTF8 while in fact, it isn't which adds even more fun into the game :-)

You can be sure that mysql_select_db() certainly is somewhere in your application. It wouldn't work without it.

http://dev.mysql.com/doc/refman/5.0/en/charset.html
(This is for MySQL 5, look around for other versions if you're running a different version.)

0

thank you all for your replies.

I have proceed to a next stage now.

for stephen84s :into this progject, i have several departments that uses different databases.in one of them, that i do my tests, i did what you tell me.
my browser has for chractet encoding greek (windows-1253) i changed it to utf8 and i get question marks instead of greek letters. (the data are from mysql). that means that my page encoding isnt utf8 right?


to petr.pavel

My mysql charset is UTF8 and i changed the colation from latin_swedish (it was default) to utf8_general_ci and set the collation of the current table-field that contains the greek letters to utf8_general_ci.
Then i imported from a text file the queries i want to add.
The result is that there are no question marks, but wherever there is a greek letter is now invisible.

i feel that i get close.
thank you

0

anyone knows a way ?

Hi Punkis, my original comment still applies. You should focus on setting charset during import and setting charset in your application for regular usage.

0

i did what you told me, but i didnt come to a solution. I googled and find out that there are so many users who did the same thing without a change. There must be something i do not do right.

P.S. When I import to mysql i do it from a notepad file that i save it to *****.sql

I used the default encoding and utf8 encoding but nothing

0

When I import to mysql i do it from a notepad file that i save it to *****.sql

Try saving it to .html, open it in Firefox/Explorer, select encoding the way stephen84s described and see if your source is all right.

Can you post here the script you use for importing? Maybe the problem is there.

Also, when you import, export it using phpMyAdmin and again, change the extension to .html, open in FF/MSIE, set encoding to verify that the import is ok.

0

Thank you petr.pavel for your support

1. I saved the following
to a html file. I uploaded in the sever and with default encoding Greek, it was displayed correctly. I changed browser encoding to UTF8 and i got question marks.
Then using Notepad again i saved it with utf-8 encoding and now it is displayed correctly with UTF8 encoding select by default to the browser.

INSERT INTO `PHPAUCTIONXL_auctions` (`id`, `user`, `title`, `starts`, `description`, `pict_url`, `category`, `minimum_bid`, `reserve_price`, `buy_now`, `auction_type`, 
`duration`, `increment`, `location`, `location_zip`, `shipping`, `payment`, `international`, `ends`, `current_bid`, `closed`, `photo_uploaded`, `quantity`, `suspended`, 
`private`, `relist`, `relisted`, `num_bids`, `sold`, `shipping_terms`, `bn_only`, `adultonly`) VALUES('5227', '5', 'Αρχίδια ΑΡΧΙΔΙΑ βραστά VSX-AX5AI-S PIONEER', 
'20080905000444', '<a target="_blank" href="http://www.atsidas.gr/Product.aspx?ID=28&MenuID=27">View more info for this item</a>', 
'http://www.atsidas.gr/ProductImages/0301000405s.jpg', '214', '0.00', '0.0000', '1100,00', '2', '55555555', '0.0000', 'Greece', 'NA', '2', 'By Mail\\nPaypal\\n', '1', 
'20240905173628', '0.0000', '0', '0', '1', '0', 'n', '0', '0', '0', 'n', 'none', 'n', 'n');

2. So, I guess some of my pages are not designed for utf8 encoding.
If it is so, that gives me two options.
A. To get the html code of all my pages, open it with notepad and encode it with utf8
B. To put the meta charset for utf8 to all of my pages. ( Have in mind that i did that for the pages that are used for the searching section, and also I did it with the combination of saving it with notepad in utf8 )

0

Also, I import some items for the importing/exporting test you told me.
I have mysql and collations to utf8 general ci

1. Using the default encoding of notepad,I import the sql file and i got question marks. i did not exported it.
2. I saved the sql with utf8 encoding now. I uploaded it and mysql displays it right. I searched it through the site and it gave me question marks again. The encoding of browser is set to UTF8. Then i exported it from mysql, saved it into html, uploaded it, opened it and with greek encoding (default is right) utf8 gives me question marks

0

1. I saved the following to a html file. I uploaded in the sever and with default encoding Greek, it was displayed correctly. I changed browser encoding to UTF8 and i got question marks.

That's understandable, only one of them will work. Just a question: is the text really in Greek language? I don't know what your nationality is so I don't know if you're saying Greek meaning "some rubbish characters" or if you're saying Greek because it really is and should be Greek alphabet. (No offence here, people call dummy fill-in text "Lorem ipsum" "Greek".)

If you want to work with UTF-8 you have to work with UTF-8 only - you can't have a part in iso-8859-7 (or what is it that you have) and part in UTF-8. There's no point in saving from notepad in anything else than UTF-8, all of your HTML pages must be saved in UTF-8 etc.

For testing if the SQL is in UTF you don't have to upload it to server. Just change the extension to .html, open the file locally in your browser, change browser encoding do UTF and see what you got.

A. To get the html code of all my pages, open it with notepad and encode it with utf8
B. To put the meta charset for utf8 to all of my pages. ( Have in mind that i did that for the pages that are used for the searching section, and also I did it with the combination of saving it with notepad in utf8 )

Well, you have to do both - all your files (that work with the UTF-8 content of your database) must both themselves be in UTF-8 and their meta charset must show that.

0

... I uploaded it and mysql displays it right. ...

You're being imprecise. What "mysql" displays it right? phpMyAdmin? or you're logged into MySQL using default command line client? If yes then what operating system you run the client on (Windows? Or do you connect to your server via ssh and there you run the command line client?) Your client or something along the way may translate the encoding so you have to provide exact information.

For instance, phpMyAdmin itself runs in some encoding (you can change that, you should be using UTF-8 - check in your browser). Then when you import using phpMyAdmin (you still didn't tell me what you use for importing) you tell phpMyAdmin what the source encoding is. The attribute you import to must also be in UTF-8 otherwise it would normally display rubbish but your browser might change its encoding based on content auto-detection without you even noticing it.

I hope you're not copy/pasting the sql into something that doesn't run in UTF-8...

0

I tried to find the file that does this work (as i said is not developed by me)
and found this :

/* this subastas title and link to details */
$tplv['id']=$row['id'];
$tplv['idformat']="<A HREF=\"".$SETTINGS['siteurl']."item.php?id=".$row['id']."\">";

$tplv['idformat'] .= stripslashes(htmlspecialchars($row['title'])); $tplv['idformat'].= "</FONT></A>";

so i guess there must be something with this

$tplv['idformat'] .= stripslashes(htmlspecialchars($row['title']));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.