dpd3447 2012-11-30 13:00
浏览 58
已采纳

使用mysql_real_escape_string后,在textarea中显示多行

I am trying to protect against sql injections by using mysql_real_escape_string before inserting data to the database:

$data=mysql_real_escape_string($_POST['data']);

Now, the data is stored as such:

That\\\'s an apostrophe.

This new line isn\\\'t displaying properly!

So, I am trying to get it to display correctly inside of a textarea after pulling it back out of mysql:

$data = nl2br($data);

For whatever reason, this does NOTHING. I've even tried str_replace to replace the 's with a <br>, but then the <br> just displays within the textarea.

How do I get what's in my mysql to display as:

That's an apostrophe.

This new line isn't displaying properly!
  • 写回答

3条回答 默认 最新

  • drt5813 2012-11-30 13:13
    关注

    you probably have magic_quotes turned on, check it with
    echo get_magic_quotes_gpc() or else you will double quote

    "Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically. "

    by the way, it's not a good ideia to use magic_quotes, try using one of this classes.

    PDO http://br2.php.net/manual/en/book.pdo.php or mysqli http://br2.php.net/manual/en/book.mysqli.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动