Jump to content

[SOLVED] mysql - php and character set problem


Recommended Posts

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

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.

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

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");

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?

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)

 

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.

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?

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);

 

 

 

 

?>

 

Yes! That was a main problem and now is solved!  :D

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?

 

 

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?!

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?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.