You are here: inserting utf8 from PHP to MySQL makes text unreadable « PHP « IT news, forums, messages
inserting utf8 from PHP to MySQL makes text unreadable

Posted by Dave on 02/01/05 09:07

PHP General,

The Situation:
I am creating a form for users to enter text into a MySQL 3.23
database. The text is often in Japanese, encoded in utf-8 format.

The Problem:
When the utf-8 encoded text is inserted into the database, it
becomes random ASCII gibberish.

What I've Tried So Far:
I've noticed that it is possible to save utf-8 encoded text in the
database. When I insert Japanese text into the database using
phpMyAdmin, it stores okay, and I can access the text via PHP for
placement on web pages. So my speculation is that there is something
wrong with my script.
My search on the web for information has turned up indication that
it should be possible to simply store utf-8 text without the need for
modifications. Some places suggest that it might be best to store the
Japanese text as binary. But since I can enter utf-8 text into fields
and store them as text successfully in phpMyAdmin, I am sure there must
be a way for getting around binary storage. I'd like to avoid binary
storage if possible, for a variety of reasons.

The Question:
How can I preserve the text so that it does not become garbled when
written to the database?

For Reference:
Here is the form and the PHP script that it accesses. $showData is
obtained by querying the database and seeing what is already stored there.

<form enctype="multipart/form-data" action="" method="POST">
<p>English (256 characters)</p>
<p><textarea name="introE" rows="5" cols="50"><?php echo
$showData['introE'];?></textarea></p>
<p>(Japanese)(256 Characters)</p>
<p><textarea name="introJ" rows="5" cols="50"><?php echo
$showData['introJ'];?></textarea></p>
<p><input type="submit" name="submit" value="submit" /></p>
<?php
if (isset ($HTTP_POST_VARS['introE']) || isset ($HTTP_POST_VARS['introJ']))
{
$updateQuery = "UPDATE events SET introE='" . $HTTP_POST_VARS['introE']
.. "', introJ='" . $HTTP_POST_VARS['introJ'] . "' WHERE eventid = " . $show;
$updateResult = mysql_query($updateQuery);
}
?>
</form>

Any help much appreciated.

--
Dave Gutteridge
dave@tokyocomedy.com
Tokyo Comedy Store
http://www.tokyocomedy.com/english/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация