德国乌姆劳斯人在MYSQL INSERT中 [英] German Umlauts in MYSQL INSERT

查看:31
本文介绍了德国乌姆劳斯人在MYSQL INSERT中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的mysql插入语句有问题. 我有一个表单,可以将utf-8字符正确提交到插入文件中(我已经检查了POST变量).

I have a problem with my mysql insert statement. I have a form which is submitting utf-8 characters correctly to the insert file (i've checked the POST vars).

现在,当我照顾数据库中的INSERT时,没有变音符号,而是问号.

Now when i look after the INSERT in my DB, there are no umlauts, but question marks.

错误必须在插入语句之前.

The error must be right before the insert statement.

如果我从数据库中输出(手动输入)内容,则会正确显示变音符号.

If i output (manually entered) content from my DB, umlauts are correctly displayed.

// echo $_POST["title"];
// outputs correctly with special chars: "Some german title with umlaute ä ö ü"

mysql_query("INSERT INTO videos (youtube_hash, title, description, category, created) VALUES ('".mysql_real_escape_string($_POST["hash"])."', '".mysql_real_escape_string($_POST["title"])."', '".mysql_real_escape_string($_POST["desc"])."', '".mysql_real_escape_string($_POST["cat"])."', '".time()."')") or die(mysql_error());

// database entry looks like this: "Some german title with umlaute ? ? ?"

我希望任何人都可以在此方面帮助我:)

I hope anyone can help me out in this :)

htmlentities()完成了任务!

推荐答案

使用HTML实体并不是解决问题的最佳方法.理想情况下,您应该将数据存储在数据库中,并且仅使用htmlentities()进行显示.如果您想以不同于HTML的其他方式显示/导出该数据怎么办?

Using HTML entities isn't the nicest solution to your problem. Ideally you should be storing data in the database and only using htmlentities() for display purposes. What if you ever wanted to display/export this data in some other way than in HTML.

我建议阅读PHP/MySQL中的字符集处理方法.这是我最近写的文章:如何避免PHP中的字符编码问题

I'd recommend reading up on character set handling in PHP/MySQL. Here's an article I wrote recently: How to Avoid Character Encoding Problems in PHP

如果仍然遇到问题,请重新发布.

Post up again if you're still having problems.

这篇关于德国乌姆劳斯人在MYSQL INSERT中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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