php mysql处理单引号,如何在PHP中的SQL查询中处理单引号?

I am using a particular query for inserting records. It is going well. I am even fetching records with a select query. But my problem is that, if the record contains single quotes ' ', then it gives me this error:

> NOTE:You have an error in your SQL syntax;

> check the manual that corresponds to your MySQL server

> version for the right syntax to use near 'B''' at line 1

The SELECT query is:

$result= mysql_query("SELECT s.name,

s.sid as sid,

s.category,

p.name as pname

FROM poet p

INNER JOIN song s

ON p.pid = s.pid

WHERE s.name= '$sid'") or die(mysql_error());

What should I do to skip quotes problem in this. When I want quotes to insert in my records.

解决方案

Your problem is much worse than this -- what if someone enters the value '; DROP TABLE poet; --? You need to use either mysql_real_escape_string() to escape the value, or use parametrized queries (with PDO, for example).

It's 2011, for crying out loud. Why is SQL injection still a widespread problem?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值