donglei7152 2009-12-10 19:46
浏览 51
已采纳

PHP无法正常转义我的字符串

I'm using mysql_real_escape_string to escape my content but I am receiving an error in a SQL INSERTION QUERY for having a single-quote unescaped. How can I resolve this?

$content = mysql_real_escape_string("'content'",$conn);

The error message I am receiving is:

You have an error in your sql syntax near 'content

My SQL Query ENDS UP BEING of the following:

$sql = "INSERT into `table` (`column`) VALUES ("'content'")

INSTEAD OF

$sql = "INSERT into `table` (`column`) VALUES ("\'content\'")

I also tried using single quotes for my delimiter and ended up failing on a double quote not being escaped.

  • 写回答

1条回答 默认 最新

  • drccfl9407 2009-12-10 19:52
    关注

    Like people said in your previous that you delete (why did you delete it, btw ? ), you need to give us more informations, like a full example that shows each steps of the construction of your query ; and, also you should give use the SQL query by itself, and the error message you get...

    Still, if you allow me quoting your previous question, you said your SQL query was the following :

    insert into `exp_weblog_data` (`entry_id`,`site_id`,`weblog_id`,`field_id_117`,`field_ft_117`,`field_id_27`,`field_ft_27`,`field_id_26`,`field_ft_26`,`field_id_28`,`field_ft_28`,`field_id_129`,`field_ft_129`,`field_id_33`,`field_ft_33`) 
    values ("","1","112","Patch 1.10","none","","none","- Fixed a bug with certain Creative Lab DVD drives and copy protection.("Unable to connect to Battle.net").","none","","none","ftp://totukati.gamezone.com/lodpatch_110.exe","none","[16020] Diablo II: Lord of Destruction","none")
    

    If it is still that same query, strings in SQL must not be delimited by double quotes ("), but by simple quotes (').

    Which means your query should look a bit more like this :

    insert into `exp_weblog_data` (`entry_id`,`site_id`,`weblog_id`,`field_id_117`,`field_ft_117`,`field_id_27`,`field_ft_27`,`field_id_26`,`field_ft_26`,`field_id_28`,`field_ft_28`,`field_id_129`,`field_ft_129`,`field_id_33`,`field_ft_33`) 
    values ('','1','112','Patch 1.10','none','','none','- Fixed a bug with certain Creative Lab DVD drives and copy protection.("Unable to connect to Battle.net").','none','','none','ftp://totukati.gamezone.com/lodpatch_110.exe','none','[16020] Diablo II: Lord of Destruction','none')
    

    Hope this helps...


    (If it's not the same question as the other post, sorry in advance)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退