Developer Developer -4 years ago 94
PHP Question

php function filtration for input form

I try to create a function to filter the input field after submit
database connection

include("includes/connect.php");


this function is like that

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


Form

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


Code

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


When i try to print the $name after filtration i don't have any result

i try to do that

strip_tags(htmlspecialchars(htmlentities($x)))


and i have an output

but for me i want to use
mysqli_real_escape_string


how can i solve this problem??!

Answer Source

You'll need to return the value from your function. :)

function filter($x) {
    // do the cleaning of your string
    return $y; 
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download