Insert into database problem… (Bad character coding) PHP/MYSQL

后端 未结 1 720
醉话见心
醉话见心 2021-01-20 12:00

I have a form which is submitted into a mysql database. The database is set to UTF-8_GENERAL and the rows are using the same character coding as well.

But when I sub

相关标签:
1条回答
  • 2021-01-20 12:53

    Its good that you are using mysql_real_escape_string()!

    I think the problem might be, that in some side-step form page -> header file -> core file -> mysql macro file -> inserting to DB etc.. If you are using some CMS method of course.

    So basically:

    1. Make sure that all your tables and cells in mysql are UTF8
    2. Add this to your mysql macro or right after you create mysql connection: mysql_query("SET NAMES utf8");
    3. Add this to your core file or on the top of your php page: Header("Content-Type: text/html; charset=UTF-8");
    4. And of course the meta-tag, that sets encoding in the html/template file.

    If you have mastered those steps, it should be fixed. If not, then at least you have debuged out alot of possible issues :)

    0 讨论(0)
提交回复
热议问题