Jump to content

Recommended Posts

I have a form where I wish for users to insert their city.  Some cities in the world are going to have foreign characters such as è in their name, and I'm wondering how I can make it so that regardless of what they type, it will be inserted into the database correctly.

 

Currently, entering the name "Trois-Rivières" returns "Trois-Rivières" for example.  Thanks for any help.

That would apply to the entire file though?  I'm actually modifying existing code.  (Invision Power Board, to be be exact.)  I'm worried that doing that will mess up something that they've written.  Is that the only solution?

all i can think off, setting the value of the inserted word of the database value.

 

making the 1 set field enter the unrecognized letter.

<?

  mysql_query("insert  table_name set field = _utf8'value'");

  //'value' came from post variable

?>

i've just been doing this. Use utf-8 character encoding in your metatags. Then when you add something to the database use

 

htmlentities('your funny text');

 

then when you want to display it:

html_entity_decode($var);

 

I had to do it that way anyway as the pages i'm using have a variety of strange and funny characters.

 

Hope that helps.

all i can think off, setting the value of the inserted word of the database value.

 

making the 1 set field enter the unrecognized letter.

<?

  mysql_query("insert  table_name set field = _utf8'value'");

  //'value' came from post variable

?>

Thanks, but this did not work.

i've just been doing this. Use utf-8 character encoding in your metatags. Then when you add something to the database use

 

htmlentities('your funny text');

 

then when you want to display it:

html_entity_decode($var);

 

I had to do it that way anyway as the pages i'm using have a variety of strange and funny characters.

 

Hope that helps.

I don't understand.  So if I want to add it to the database, I would do this?

 

//$variable = "Trois-Rivières";
$variable2 = htmlentities('$variable');

 

And then insert $variable2 to the database?  Because, it is just inserting the word "$variable" and not the actual content of it.

You'll need the table's collation to be UTF-8, you'll need to set the connection to UTF-8, you'll need to tell the browser that it's UTF-8 and when using functions like htmlentities you'll have to tell it that it is UTF-8.

 

Generally, you need to make sure you use the same character set throughout the entire process.

I removed the single quotes, and it's still adding to the database incorrectly.  While before it added characters like è, it is not adding stuff like è

 

You'll need the table's collation to be UTF-8, you'll need to set the connection to UTF-8, you'll need to tell the browser that it's UTF-8 and when using functions like htmlentities you'll have to tell it that it is UTF-8.

 

Generally, you need to make sure you use the same character set throughout the entire process.

Okay, any UTF-8 specifically?  Currently, the table's collation is set to utf8_unicode_ci.  I also have the field set to that.

 

I'm not familiar with how to set the other three (connection, browser, and htmlentities) to UTF-8 as well.  Please explain?

Well, you can set the MySQL connection to UTF-8 by running this query after connecting:

SET NAMES utf8;

 

You set it in the browser like this:

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

 

And as described on htmlentities's manual page, you do something like this:

htmlentities($string, ENT_COMPAT, 'UTF-8');

Well, you can set the MySQL connection to UTF-8 by running this query after connecting:

SET NAMES utf8;

 

You set it in the browser like this:

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

 

And as described on htmlentities's manual page, you do something like this:

htmlentities($string, ENT_COMPAT, 'UTF-8');

 

Cool, I only changed the last one (like I said, I can't change the others because I don't want to mess up something else in the IPB software.)

 

The è now enters the database as a è

 

This isn't exactly what I was going for, but it seems to work just as well.  When I call the information from the database, it automatically converts it to an è, as far as I can tell.  Unless doing it this way would create some additional consequence that I'm not even considering?

 

Thanks for the help!

Well, in my opinion you shouldn't insert HTML escaped data into the database. If you're having trouble with IPB you should contact their support department. Especially considering you are actually paying them.

Why would it be bad to do this, in your opinion?

 

As far as IPB goes, I'm modding their product to do things it wasn't originally intended to do.  They have no obligation to help me.

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.