vmavrou Posted November 18, 2009 Share Posted November 18, 2009 hi! i have this problem.. i want to use the utf-8 as the charset of my site and db on every page i have this : <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> and at the configuration file which i include also in every file with : include_once("mysql_work.php"); i have in this : $dbhost = 'localhost'; $dbuser = 'test'; $dbpass = 'ts'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_query("SET NAMES 'utf8'", $conn); also at the phpmyadmin every collation i have put it as utf8_unicode_ci But it's not working. Any ideas what am i doing wrong? Maybe is something with the include of the configuration file,because at the index.php works but at the other pages stops workings.. Also i'm not sure if this mysql_query("SET NAMES 'utf8'", $conn); is right or need and something else.. I don't know if i explain it very well..if you don't understand anything, i can give more info. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/ Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 Try calling... mysql_query("SET CHARACTER SET 'utf8'", $conn); ... directly after... mysql_query("SET NAMES 'utf8'", $conn); If that doesn't work do you have a live server we can see it on?! Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960179 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 unfortunatelly it remains the same.. what do you mean by live server? the site is here http://vmavrou.freetzi.com/index.php at the index works,but when you click a button then the problem starts Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960185 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 Looking at your site, despite the fact you have the meta tag present the header for Content-Type doesn't appear to be sending. If I'm honest I can't say I know exactly why. Looking at your source you don't have a doctype, the first thing I'd test out would be adding a doctype. I'd then try adding setting the Content-Type header using using the PHP header function rather than through HTML, just to see if it makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960193 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 well at the index.php there is the <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> and i added to the rest but i see no change i don't know if there is a problem with this doctype,it was added by dreamweaver i think i haven't enter it and i don't know if i have to make any change? I will now try your other suggestion with the header() and will be back with the results. Really thankfull for your time and help Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960198 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 well by using : <?php header('Content-type: text/html; charset=utf-8'); ?> it's even worst,check out index.php now it shows and this one with problem. Well it makes me confused with the same lines (without the header) <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> the index.php works and then the rest not. That's why i'm thinking if there is something that makes a kind of reset at the settings of the db? Also i remind that i include the configuration file in every page with the include_once("mysql_work.php"); Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960208 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 Your index.php looks better at the moment than it did last time, the Á.Ô.Å.É ÈÅÓÓÁËÏÍÉÊÇÓ characters weren't displaying before. Is all the PHP actually on the same page or does it use includes to display the information? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960224 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 well it includes some info, as the login box at the left top, but at the middle, adove the logo there is a search box, and there there is a greek word for search that is not included, it is at the index and it's not showing it correct. also at the mysql settings from the phpmyadmin : MySQL connection collation: Collation utf8_unicode_ci Characted set of mysql : UTF-8 Unicode (utf8) Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960242 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 What I meant was is any element on the page actually in a different PHP file and displayed using an include or require statement? If they are it's possible you may have to send a header as part of each file/script. Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960253 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 I have insert it but it's still the same, also i meant that at least the word for the search button should at least work,but not even this one Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960256 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 What editor are you using for your file? What encoding type is it saved with? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960271 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 well now for any changes i make the with notepad... does this matter? i didn't know it.. Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960281 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 I'm assuiming that the text on the buttons on the index page aren't populated using data from your database? They are just text that you have entered in your editor? That being the case I suspect that could have a lot to do with it. On a side note I just checked the headers of your page now, they are now saying utf-8, which is a move in the right direction. Can you upload your script as an attachment? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960302 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 The e exam and examino 3 are imported from the database,the other button for the search button is plain text. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960317 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 and the mysql_Work.php <?php $hostaddr = "http://vmavrou.freetzi.com/"; $adminupload= $hostaddr."admin/upload/"; $defaultupload= $hostaddr."upload/"; $dbhost = 'localhost'; $dbuser = 'test'; $dbpass = 'ts'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_query("SET NAMES 'utf8'", $conn); mysql_query("SET CHARACTER SET 'utf8'", $conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960323 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 The characters aren't correct in my editor, they come up as ���������, which indicates the encoding of the file is wrong. IN notepad, click save as and make sure the encoding is set to UTF-8. Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960329 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 Yes! That was a main problem and now is solved! Great,thank you very very much. If you have time,now the remaining problem is the ????? at the index.php this text is given by the user and it's saved at the db,and then is imported from there. at the code that is for adding the text i use again : <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> tried also and the header(), saved utf-8 if(isset($_POST['stext'])) { $newtext = $_POST['stext']; $query = "UPDATE settings SET content = '$newtext' WHERE text = 'yes'"; $result = mysql_query($query); $stext = $newtext; at the phpmyadmin the field content is text and the charset utf8_unicode_ci When i enter it by hand at the phpmyadmin it was exported and printed fine. But when i try to insert it from the form it is saved like ?????????? like now at the main page. Any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960346 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 So what your saying is, when you submit it with your form if you check in PHPMyAdmin, the values don't appear correctly? Or are you saying that when you submit it with your form it looks ok in PHPMyAdmin but when displayed on your form it looks incorrect?! Either way, that section had this content "Á.Ô.Å.É ÈÅÓÓÁËÏÍÉÊÇÓ" earlier when I checked it, so does that mean it was working?! Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960359 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 Yep,it's working, but the the problem is that when i submit it with the form then at the phpmyadmin value is not correct,is like ????????. It works only if i edit myself the field into phpmyadmin and enter the greek value. The it shows it fine. Is a problem at the storage now? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960363 Share on other sites More sharing options...
cags Posted November 18, 2009 Share Posted November 18, 2009 Are you calling... mysql_query("SET CHARACTER SET 'utf8'", $conn); mysql_query("SET NAMES 'utf8'", $conn); ... before updating the database as well as before reading from it? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960378 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 here i use require_once (mysql_work.php) where set character and set names are included,at the page that updates the db.at the page that reads i have include_once. Does it makes any difference? Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960384 Share on other sites More sharing options...
vmavrou Posted November 18, 2009 Author Share Posted November 18, 2009 Finally figure it out,the problem was a bad declaration at tha phpmyadmin . Thank you very much for your time and your help. Really gratefull,it was very hard to find out what was wrong. respect Quote Link to comment https://forums.phpfreaks.com/topic/182036-solved-mysql-php-and-character-set-problem/#findComment-960410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.