输入表单的php函数过滤

开发商

我尝试创建一个函数来在提交数据库连接后过滤输入字段

include("includes/connect.php");

这个功能是这样的

<?php
function filter($x){
    global $conn;
    $y=strip_tags(htmlspecialchars(htmlentities(mysqli_real_escape_string($conn,$x))));
}
?>

形式

<form method="post">
<input type="text" name="txt_name">
<input type="submit" name="add" value="Add">    
</form>

代码

<?php
if(isset($_POST['add'])){
   $name= filtration($_POST['txt_name']);
   echo $name;
}
?>

当我尝试在过滤后打印 $name 时,我没有任何结果

我试着这样做

strip_tags(htmlspecialchars(htmlentities($x)))

我有一个输出

但对我来说我想用 mysqli_real_escape_string

我怎么解决这个问题??!

丹尼尔·马克伦德

您需要从函数中返回值。:)

function filter($x) {
    // do the cleaning of your string
    return $y; 
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章