插入数据库问题...(错误字符编码)PHP / MYSQL [英] Insert into database problem... (Bad character coding) PHP/MYSQL

查看:92
本文介绍了插入数据库问题...(错误字符编码)PHP / MYSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单提交到mysql数据库。
数据库设置为UTF-8_GENERAL,行也使用相同的字符编码。



但是当我提交一个ő或ű在文本中,它不提交任何后这些字符。
(例如:这是一个不错的日子,它只是将它插入到db:这是一个很好的)



表单验证页有
mysql_real_escape_string();
strip_tags();
,然后再提交到db。



我如何解决这个问题?
任何帮助赞赏...

解决方案

你使用mysql_real_escape_string b
$ b

我认为问题可能是,在一些侧面的页面 - >头文件 - >核心文件 - > mysql宏文件 - >插入到DB等。如果你使用一些CMS方法当然。



基本上:


  1. 你的表和单元格在mysql是UTF8

  2. 添加到你的mysql宏或创建mysql连接后: mysql_query(SET NAMES utf8); code>

  3. 将此文件添加到您的核心文件或php页面顶部: Header(Content-Type:text / html; charset = UTF-8);

  4. 当然还有元标记,用于设置html /模板文件中的编码。

如果你已经掌握了这些步骤,它应该是固定的。如果没有,那么至少你已经调试了很多可能的问题:)


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 submit the form with a "ő" or "ű" in the text, it does not submit anything after these characters. (Example: "This is a nice ű day." It just inserts this into the db: "This is a nice")

The form validation page has the mysql_real_escape_string(); strip_tags(); before submitting to the db.

How could I solve this? Any help appreciated...

解决方案

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 :)

这篇关于插入数据库问题...(错误字符编码)PHP / MYSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆