?
Solved

Clean up registration and login names etc  before inputting in mysql

Posted on 2011-09-24
3
Medium Priority
?
282 Views
Last Modified: 2013-12-13
Hi,
I am trying to clean up my html form inputs before they hit mysql.
Is this possible as I've shown below? (It's not currently working?)
If it will work have I missed anything?
Thanks

$username=  sanitise($_POST['username']);

Open in new window


function sanitise($string) {
  $string = trim($string);
  $string = htmlentities($string);
  $string = strip_tags($string);
  $string = mysqli_real_escape_string($string);
  
  return $string;
}

Open in new window

0
Comment
Question by:encodeme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 280 total points
ID: 36592518
PHP has built-in functions for this.  Look up filter_var() to learn more.  You will still need to use the escape_string functions.
0
 
LVL 9

Assisted Solution

by:ghodder
ghodder earned 220 total points
ID: 36592528
function sanitise($string) {
  return mysqli_real_escape_string(trim(htmlentities(strip_tags($string))));
}

Open in new window

0
 

Author Closing Comment

by:encodeme
ID: 36592693
H'm I didn't know those functions existed.

I appreciate the code tweaks... never thought of doing it inline.

thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question