Jump to content

[SOLVED] Is there an easy way to prevent SQL injection?


3motions

Recommended Posts

Do you guys know of any easy ways to prevent SQL injections in my PHP forms? Such as stripping out certain characters, etc? The reason I say easy is because I've already nearly completed programming my website without once thinking of preventing SQL injections, and I don't want to have to reprogram a lot of my codes to implement it. Thanks!

Nope, I don't have any functions or anything. Am I able to add that to maybe $_POST calles, such as, "mysql_real_escape_string($_POST['username'])" or something? That way I can just add it to where the post is called in the script?

Be warned though, if magic_quotes are on and you use mysql_real_escape_string(), it can stuff things up. Instead of using mysql_real_escape_string(), pass the things you wish to clean through this function instead:

 

function clean_string( $value ) {
	if ( get_magic_quotes_gpc() )
		$value = stripslashes( $value );
	return mysql_real_escape_string( $value );
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.