/    Sign up×
Community /Pin to ProfileBookmark

striptags() & stripslashes() & htmlspecialchars() Still Needed ?

Folks,

Is it really necessary to filter user inputs to my webform using the stripslashes and striptags PHP functions since user inputs will be dumped to my MySql dB using prepared statements ?
Even though I will be using prepared statements, should I still code like the following a filter to filter the user inputted data before dumping the data to my MySql dB using prepared statements ? That is the big question tonight.

[code]
<?php
// define variables and set to empty values
$name = $email = $gender = $comment = $website = “”;

if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$name = test_input($_POST[“name”]);
$email = test_input($_POST[“email”]);
$website = test_input($_POST[“website”]);
$comment = test_input($_POST[“comment”]);
$gender = test_input($_POST[“gender”]);
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
[/code]

Or maybe I should just use the htmlspecialchars() filter only here ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorMay 21.2021 — @NogDog,

What would you do in this position, mate ?
Copy linkTweet thisAlerts:
@developer_webauthorAug 07.2021 — I still have the same question. Who's gonna give me the answer so I can get this thread closed ?
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...