0

Having an issue with strange characters showing up when inserting into a database, have tried tirelessly to figure out the issue but I am out of ideas...

Basically if I insert this data like so (this is just testing):

  $valy = "…industry's favorite </em><strong><em>party of the year</em></strong><em>, </em><a href='http://www.unitingagainstlungcancer.org/getinvolved/strolling-supper-with-blues-news'><span class='s1'><em>Joan's…";
  $valy = mysql_real_escape_string($valy);

  $query = "INSERT INTO test_table (data) VALUES ('".$valy."')";
  mysql_query($query,$dbhandle);

this will end up in the database (notice the A characters):

"...industry's favorite party of the year, http://www.unitingagainstlungcancer.org/getinvolved/strolling-supper-with-blues-news'>Joan's..."

I have tried to line up all the character settings:

php default_charset = utf-8
mysql table & row charset = utf-8
Mysql instance variables:
character set client    utf8
(Global value)  latin1  
character set connection    utf8    
(Global value)  latin1  
character set database  latin1  
character set filesystem    binary  
character set results   utf8    
(Global value)  latin1  
character set server    latin1  
character set system    utf8    

What could this issue be?

1

2 Answers 2

2

One thing you may be missing is when you setup the connection. There you should also set the encoding to utf8.

Example:

$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);

However, don't use the mysql extension, it's deprecated: http://php.net/manual/en/function.mysql-set-charset.php

Sign up to request clarification or add additional context in comments.

Comments

1

Try to set the mysql connection to UTF-8 as well:

mysql_query("SET NAMES 'utf8'");

2 Comments

You don't want to do it every single time.
You can set it right after you connected to the database, than you don't have to do it every single time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.