doubi8512 2015-06-19 20:35 采纳率: 0%
浏览 18

Mysql / php处理左/右引用与常规引号不同,如何阻止它?

I am having trouble submitting form data to my mysql database. Mysql/Php seems to be treating the open and closed quotes (a.k.a. “ and ”) differently from other characters such as your regular (") or even (<) (>) or (&).

What gets submitted to my database is &#8220 and &#8221 and I don't want that. I want open and closed quotes to appear just like any other character. What is odd is that if I hit the "back button" on my browser and resubmit the same post, I will get what I want submitted to my database. But I want the (“) and (”) to submit correctly on the first try.

I haven't tested all characters to see which work and which don't, but I have tested some and it appears only the open and closed special quotes are the only ones giving trouble.

Here is my query structure:

$content = mysql_real_escape_string($_POST['content']);
$topictitle = mysql_real_escape_string($_POST['topictitle']);
$topiccategory = mysql_real_escape_string($_POST['topiccategory']);
$date = date('Y-m-d H:i:s');
$query = "INSERT INTO `ttable` (`topictitle`,`user`,`cat`,`postcontent`,`posttime`,`replylast`) VALUES ('".$topictitle."','".$_SESSION['user']."','".$topiccategory."','".$content."','".$date."','".$date."')";

My form is really long and I dont think it will be relevant so I won't post that.

Any idea what might cause this behavior?

Note: mysql_real_escape_string does not seem to be escaping the open/close quotes...

Update: Changing my method to "get" instead of "post" so I can see my view source...the $_GET['content'] view source shows the code, not the quote. So something must be happening before I even get to the mysql query page. I still can't see why it converts the special quote to a code. I haven't done anything to it.

UPDATE2: I put a string_replace in right before the mysql query and right after the mysql_real escape string. I figured that I could at least replace all instances of &#8220 and &#8221 with left and right quotes again. Instead, now what I get in my database is....“ and †... so there's definitely something funny goin on...

UPDATE3: UPDATE2 was missing the fact that I put this (

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

) at the head of my page when that happened.

UPDATE4: This looks like a similar problem, but doesnt fix mine. Putting the meta tag at the top of the pages creates a new problem where special quotes get turned into “ and †... I should perhaps note that I am on a mac.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。
    • ¥15 livecharts wpf piechart 属性
    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题