Jump to content

[SOLVED] Garbled characters in database.


Petsmacker

Recommended Posts

I'm having a problem where if I input special characters such as any foreign characters or

– (this is an em-dash)

 

They go into the database as something along the lines of “ or another character might come out as •. I output the strings at every point before they go into the database and they seem to be fine so I'm assuming its an SQL problem.

 

Both my META and PHP header tags are set to UTF-8. I also put my database as UTF-8 to see if that'd help but no.

 

I'm still very confused as to the whole characters vs  encoding thing so maybe UTF-8 isn't even on the same page as the issue I'm trying to resolve.

Any ideas?

Link to comment
Share on other sites

Yeah, they are in the UTF-8 charset and I made my database UTF-8, the table UTF-8, the row UTF-8. So I've had to rule out that issue. I have no idea why for example, bullet points:

• come out as •

 

I've output the Query that has been sent to the database and its fine.

UPDATE temp2 SET thing='••••'

When I do this via phpMyAdmin, it goes through as it should and •••• is in the database. However, when I perform the query on a normal PHP page, thats when it becomes garbled.

 

Does anyone really not have any idea as to why?

Link to comment
Share on other sites

When I do this via phpMyAdmin, it goes through as it should and •••• is in the database.

 

When you perform a query in PHPMyAdmin it will also show you the exact code it used to perform the action. So to reproduce the successful result, in theory, all you'd need to do is copy/paste whatever PHPMyAdmin is doing and use that in your SQL query which you execute via PHP.

Link to comment
Share on other sites

I've FINALLY solved the issue. My second-to-last post, I misunderstood what I needed to do.

 

If anyone else is having this problem, you need to add:

mysql_query("SET NAMES 'utf8'");

 

After your mysql connect area like so:

 

mysql_connect("$localhost","$db_user","$db_pass");

@mysql_select_db("$db_name");

mysql_query("SET NAMES 'utf8'");

 

Now, when you enter special characters in the DB, they'll come out as they should. Enjoy!

Link to comment
Share on other sites

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.