[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 574
  • Last Modified:

How to store Korean data with UTF-8 Encoding from Web Form

Hello all,

I'm caught in the mire of UTF-8 encoding, I guess.  I've got a database working well for a Korean client, that stores mostly regular English characters, (names, phone numbers, email, etc.), but also has one field for the Korean name of the person.

I've researched for several hours, trying to figure out how to properly handle this.  I see that the best way seems to be to keep things in UTF-8 encoding.  The database is relatively small, with mainly 4 tables, mainly two with most of the data.  I did not create it with UTF-8 encoding.  A few days ago, I changed a number of the fields to UTF-8 in the main table, using Navicat.  The Korean characters look right in that field.  

Yesterday I also was able to make one page display the Korean characters properly.  It took adding mysql_query("SET NAMES 'UTF8'"); in several places to make it happen.

My problem now is in a form where people edit a row of data.  The Korean characters show up properly in the input box when the data is pulled in, but when the update button is hit, the table now has garbage data in place of the Korean characters.  I'm assuming that the form is somehow not submitting the data in UTF-8 character encoding, though I may be wrong.  

I have

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

in place on the page.

I'll post the code for the form here as well.  Some of the code has been generated by Dreamweaver and ADDT.

Thanks in advance for any help on this frustrating issue.

Karey
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" enctype="multipart/form-data" accept-encoding="UTF-8">
  
    <table cellpadding="2" cellspacing="0" class="KT_tngtable">
      <tr>
        <td valign="middle" class="KT_th"><label for="lastname">Last Name:</label></td>
        <td><input name="lastname" type="text" id="lastname" style="font-size:22px" value="<?php echo KT_escapeAttribute($row_rsindividuals['lastname']); ?>" size="35" />
          <?php echo $tNGs->displayFieldHint("lastname");?> <?php echo $tNGs->displayFieldError("individuals", "lastname"); ?></td>
      </tr>
      <tr>
        <td valign="middle" class="KT_th"><label for="firstname">First Name:</label></td>
        <td><input name="firstname" type="text" id="firstname" style="font-size:22px" value="<?php echo KT_escapeAttribute($row_rsindividuals['firstname']); ?>" size="35" />
          <?php echo $tNGs->displayFieldHint("firstname");?> <?php echo $tNGs->displayFieldError("individuals", "firstname"); ?></td>
      </tr>
      <tr>
        <td valign="middle" class="KT_th">Korean Name:</td>
        <td><input name="koreanname" type="text" id="koreanname" style="font-size:22px" value="<?php echo KT_escapeAttribute($row_rsindividuals['korean_name']); ?>" size="35" />
          <?php echo $tNGs->displayFieldHint("koreanname");?> <?php echo $tNGs->displayFieldError("individuals", "koreanname"); ?></td>
        </tr>
      <tr>
        <td valign="middle" class="KT_th"><label for="cell_phone">Cell Phone:</label></td>
        <td><input name="cell_phone" type="text" id="cell_phone" style="font-size:22px" value="<?php echo KT_escapeAttribute($row_rsindividuals['cell_phone']); ?>" size="32" />
          <?php echo $tNGs->displayFieldHint("cell_phone");?> <?php echo $tNGs->displayFieldError("individuals", "cell_phone"); ?></td>
        </tr>
      <tr>
        <td valign="middle" class="KT_th">Email:</td>
        <td><input name="email" type="text" id="email" style="font-size:22px" value="<?php echo KT_formatDate($row_rsindividuals['email']); ?>" size="32" />
          <?php echo $tNGs->displayFieldHint("email");?> <?php echo $tNGs->displayFieldError("individuals", "email"); ?></td>
        </tr>
      <tr>
        <td valign="middle" class="KT_th"><label for="birthdate">Birthdate:</label></td>
        <td><input name="birthdate" type="text" id="birthdate" style="font-size:22px" value="<?php echo KT_formatDate($row_rsindividuals['birthdate']); ?>" size="15" />
          <?php echo $tNGs->displayFieldHint("birthdate");?> <?php echo $tNGs->displayFieldError("individuals", "birthdate"); ?></td>
        </tr>
      <tr>
        <td valign="middle" class="KT_th"><label for="head">Head of Household:</label></td>
        <td><input  <?php if (!(strcmp(KT_escapeAttribute($row_rsindividuals['head']),"1"))) {echo "checked";} ?> type="checkbox" name="head" id="head" value="1" />
          <?php echo $tNGs->displayFieldError("individuals", "head"); ?></td>
        </tr>
      <tr class="KT_buttons">
        <td colspan="2"><input type="submit" name="KT_Update1" id="KT_Update1" value="Update record" /></td>
        </tr>
      </table>
    <input type="hidden" name="family_id" id="family_id" value="<?php echo KT_escapeAttribute($row_rsindividuals['family_id']); ?>" />
    </p>
  </form>

Open in new window

0
ImagineItDigital
Asked:
ImagineItDigital
  • 4
  • 2
  • 2
1 Solution
 
profyaCommented:
You did great job. I think the problem is not with the encoding of the page, rather it is with the file format. When you shift the encoding of the page to UTF-8 you need also to save the file as UNICODE or UTF-8, it is saved now as ASCII I guess. Using the text editor you can SAVE the file AS UTF-8 and I hope the problem fixes.
0
 
ImagineItDigitalAuthor Commented:
Thanks Profya,

But I upload the files using Dreamweaver CS4, and it is set to upload in Unicode (UTF-8).  There is also a Unicode Normalization Form setting, currently set to C.  That may not apply - not sure what it is.

So I'm still stuck.  Any other ideas?

Karey


0
 
profyaCommented:
Ok, just make sure that UTF-8 is written in the bottom right corner of the page, in the bar showing your HTML tags. This tells you whether you are using UTF-8 or not. You may need to reload your page to make sure that the file itself is saved as UTF-8. Or you can use any other simple text editor such as NotePad.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
ImagineItDigitalAuthor Commented:
Yes it is written there in the bottom right.
0
 
virmaiorCommented:
where is the code that inserts from this form into the db?
0
 
ImagineItDigitalAuthor Commented:
// Make unified connection variable
$conn_cornerstone = new KT_connection($cornerstone, $database_cornerstone);

// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger

// Make an update transaction instance
$upd_individuals = new tNG_update($conn_cornerstone);
$tNGs->addTransaction($upd_individuals);
// Register triggers
$upd_individuals->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_individuals->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_individuals->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php");
// Add columns
$upd_individuals->setTable("individuals");
$upd_individuals->addColumn("family_id", "NUMERIC_TYPE", "POST", "family_id");
$upd_individuals->addColumn("korean_name", "STRING_TYPE", "POST", "koreanname");
$upd_individuals->addColumn("email", "STRING_TYPE", "POST", "email");
$upd_individuals->addColumn("firstname", "STRING_TYPE", "POST", "firstname");
$upd_individuals->addColumn("lastname", "STRING_TYPE", "POST", "lastname");
$upd_individuals->addColumn("cell_phone", "STRING_TYPE", "POST", "cell_phone");
$upd_individuals->addColumn("birthdate", "DATE_TYPE", "POST", "birthdate");
$upd_individuals->addColumn("head", "CHECKBOX_1_0_TYPE", "POST", "head");
$upd_individuals->setPrimaryKey("individual_id", "STRING_TYPE", "GET", "individual_id");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
mysql_query("SET NAMES 'UTF8'");
$rsindividuals = $tNGs->getRecordset("individuals");
$row_rsindividuals = mysql_fetch_assoc($rsindividuals);
$totalRows_rsindividuals = mysql_num_rows($rsindividuals);
0
 
virmaiorCommented:
okay, can you post the actual query being submitted (it should be happening in $tNGs->executeTransactions();)?

also, you might want to put the SET NAMES code above your executeTransactions();
0
 
ImagineItDigitalAuthor Commented:
That did it!  Just the placement of the Set Names.

Thanks a million!
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now