Jump to content

[SOLVED] how to use this function


b2k

Recommended Posts

Hi,

 

I found this function for prevent SQL injection. But I don't know how to use it

 

<?php
function sql_sanitize( $sCode ) {
if ( function_exists( "mysql_real_escape_string" ) ) {		// If PHP version > 4.3.0
	$sCode = mysql_real_escape_string( $sCode );		// Escape the MySQL string.
} else { // If PHP version < 4.3.0
	$sCode = addslashes( $sCode );				// Precede sensitive characters with a backslash \
}
return $sCode;							// Return the sanitized code
}
?>

 

Here are my vars:

 

$name=$_POST['name'];
$email=$_POST['email'];

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/110071-solved-how-to-use-this-function/
Share on other sites

<?php
function sql_sanitize( $sCode ) {
if ( function_exists( "mysql_real_escape_string" ) ) {		// If PHP version > 4.3.0
	$sCode = mysql_real_escape_string( $sCode );		// Escape the MySQL string.
} else { // If PHP version < 4.3.0
	$sCode = addslashes( $sCode );				// Precede sensitive characters with a backslash \
}
return $sCode;							// Return the sanitized code
}

$name = sql_sanitize($_POST['name']);
$email = sql_sanitize($_POST['email']);
?>

 

Ray

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.