Jump to content

Recommended Posts

Guys, I'm not exactly sure whether this problem can be resolved using PHP or MySQL but here it is:

 

The content of my site is in Vietnamese.  I need to store the Vietnamese data in MySQL, so in MySQL, I set the Collation to utf8_general_ci and the Vietnamese language appears fine.  However, when I perform database query and display these data on the browser, they appear corrupted.  In my HTML DOCTYPE declaration, I set "charset=utf-8".  Any ideas ?  Thanks.

I think you are supposed to set the charset in a meta tag, not the doctype declaration, like so

 

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

 

but I could be wrong. just did a google search and this line of code came up in one of the pages

You also need to set NAMES and CHARACTER SET to UTF-8. Run these queries just after you've connected to your database:

 

mysql_query("SET NAMES 'utf8'", $connection);
mysql_query("SET CHARACTER SET 'utf8'", $connection);

Did you store the MySQL link identifier returned by mysql_connect() in $connection prior to running the queries? A last thing to try could be to set the header:

 

header('Content-type: text/html; charset=utf-8');

If it still doesn't work, I don't know what to tell you. It should work if you do the things right that you and I have outlined.

Thanks thebadbad, it worked.  But, now I'm having another related problem.  I have written some PHP code to handle document upload.  Because the document file names are in Vietnamese, after the uploading process is complete, the font in the filenames got corrupted.  I have used PHP "echo" command to track the errors.  What I found is that:

 

// filename appeared fine here - just before the move_uploaded_file() gets executed

move_uploaded_file($_FILES['doc_' . $i]['tmp_name'], $uploadPath);

 

Once the move_uploaded_file() got executed, I checked the document in the uploaded folder, it did get uploaded but, now, its filename got corrupted.  Any ideas ?  Thanks.

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.