Petsmacker Posted April 6, 2009 Share Posted April 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/ Share on other sites More sharing options...
aschk Posted April 6, 2009 Share Posted April 6, 2009 And you're sure that your database tables are using UTF-8 and that the characters in question are valid in the utf-8 charset? Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/#findComment-802153 Share on other sites More sharing options...
Petsmacker Posted April 6, 2009 Author Share Posted April 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/#findComment-802997 Share on other sites More sharing options...
Petsmacker Posted April 7, 2009 Author Share Posted April 7, 2009 Can't modify post anymore. Just in case someone was about to suggest it: SET NAMES 'utf8' UPDATE temp2 SET thing='••••' Doesn't work either. I'm going absolutely insane because I can't continue my project until this issue is resolved... Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/#findComment-803047 Share on other sites More sharing options...
batch Posted April 7, 2009 Share Posted April 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/#findComment-803051 Share on other sites More sharing options...
Petsmacker Posted April 7, 2009 Author Share Posted April 7, 2009 My query on the PHP page and the one I use in phpMyAdmin (including the query it shows after its executed) are both completely the same, the problem seems to be exclusive to queries performed on the PHP page. Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/#findComment-803059 Share on other sites More sharing options...
Petsmacker Posted April 7, 2009 Author Share Posted April 7, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/152728-solved-garbled-characters-in-database/#findComment-803064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.