Solved

Clean up registration and login names etc  before inputting in mysql

Posted on 2011-09-24
3
280 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 110

Accepted Solution

by:
Ray Paseur earned 70 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 55 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 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