MySQL/PHP问题与“和 ' [英] MySQL / PHP problem with " and '

查看:60
本文介绍了MySQL/PHP问题与“和 '的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP和MySQL制作了一个带有注释的简单新闻系统,它在我的本地Apache服务器(在Fedora 10机器和Windows 7上)上都非常有效.现在,我遇到了一个问题,我将其上传到了网络托管服务商,并不断返回所有的'和'作为\'和\.

我相信这是出于安全原因自动添加它们的Web主机,还是MySQL是错误的归类,但是我还无法解决它,无法测试多个MySQL归类.

这是一个查询示例:

I made a simple news system with comments using PHP and MySQL, and it worked great on my local Apache server, both on my Fedora 10 machine, and my Windows 7 one. Now I have a problem though, I uploaded it to a web host and it keeps returning all the ' and " as \' and \".

I believe this is either the web host who by automatic adds them for security reasons or that the MySQL is the wrong collation, but I have not been able to resolve it yet, testing multiple MySQL collations.

Here is a example of a query:

mysql_query("INSERT INTO news (title, poster, text, time) VALUES ('$newstitle', '1', '$newstext', '$time')") or die(mysql_error());

$timetime(); $newstitle$newstext是从$_POST解析的,并且都在运行查询之前都通过mysql_real_escape_string()运行(我想这可能是问题所在,但是由于它是安全性的一部分,我只是不想删除它,因为它在我的本地服务器上没有引起问题)

$time is time(); $newstitle and $newstext are parsed from $_POST and both are ran through mysql_real_escape_string() before I run the query (I guess this might be the problem, but since it is a part of the security I just don't want to remove it, and since it did not cause problems on my local servers)

最后一点:在我的本地apache服务器上,我的latin1_swedish_ci在网络主机服务器上不起作用.

As a final note: On my local apache servers I had latin1_swedish_ci which did not work on the web hosts server.

它们在数据库中看起来像这样:

They look like this in the database:

\'\'\'\"\"\"

在我的本地计算机上,它们没有多余的反斜杠,因此必须是PHP添加的.除了添加删除多余反斜杠的功能外,还有什么方法可以解决此问题?

While on my local ones they didn't have the extra backslash, so it must be the PHP adding it. Is there any way to solve this except adding a function that removes extra backslashes?

推荐答案

这些其他反斜杠可能是禁用或删除它们.

These additional backslashes are probably Magic Quotes. Try to disable them or remove them before processing the data.

这篇关于MySQL/PHP问题与“和 '的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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