Loganathan Natarajan
Loganathan Natarajan

Reputation: 340

How can I validate user input in simple way?

I have the below function to validate the user input. Can you suggest whether it is OK or not? I just need simple way of validating user input. no need complex way.

function cleanData($data) {
    $data = trim($data);
    $data = htmlentities($data);
    $data = mysql_real_escape_string($data);
    return $data;
}

Upvotes: 1

Views: 120

Answers (1)

mario
mario

Reputation: 145482

That's not a validation function. Your cleanData() function just escapes content. And it mixes HTML escaping with SQL escaping, where you should be applying each individually on a per use basis.

That approach is unprofessional, but in fact functional. (We've seen worse here). You do cover the common issues by using it. If you do in fact apply it to every incoming variable.

Upvotes: 1

Related Questions