mysql - 关于php函数addslashes的一些小疑问
伊谢尔伦
伊谢尔伦 2017-04-10 16:37:56
0
1
420

我把用户通过post发过来的数据"my'name"通过addslashes函数进行过滤,然后存入mysql。
但是当我在php脚本页面执行
$conn = new mysqli('127.0.0.1','root','','book_sc');
$re = $conn->query("select * from sc where title='"."my'name"."'");
var_dump($re->num_rows); //返回是NULL

但是在mysql里执行命令
mysql> select * from sc where title="my'name";
或者
mysql> select * from sc where title="my\'name";
都可以查询到这条数据,那为什么在php脚本页面执行就返回null呢?
还有就是过滤的函数还有strip_tags、htmlspespecialchars分别用于过滤掉html、php代码和转义html代码以保证数据的安全性,那我是不是需要把这3个函数都用上?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

répondre à tous(1)
左手右手慢动作

我很奇怪你执行 $re = $conn->query("select * from sc where title='"."my'name"."'");
怎么没有报错? 很明显这sql就有错误。
应该这样 $conn->query("select * from sc where title='my\'name'")

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!