What's Here?
- Members: 137,219
- Replies: 481,452
- Topics: 75,056
- Snippets: 2,567
- Tutorials: 675
- Total Online: 2,231
- Members: 105
- Guests: 2,126
|
"Sanitize" a string of SQL code to prevent SQL injection.
|
Submitted By: sandman85048
|
|
Rating:
   
|
|
Views: 4,722 |
Language: PHP
|
|
Last Modified: December 31, 1969 |
Snippet
/*
Function: sql_sanitize( $sCode )
Description: "Sanitize" a string of SQL code to prevent SQL injection.
Parameters: $sCode: The SQL code which you wish to sanitize.
Example: mysql_query('UPDATE table SET value="' . sql_sanitize("' SET id='4'") . '" WHERE id="1"');
Requirements: PHP version 4 or greater
*/
function sql_sanitize( $sCode ) {
if ( function_exists( "mysql_real_escape_string" ) ) { // If PHP version > 4.3.0
} else { // If PHP version < 4.3.0
$sCode = addslashes( $sCode ); // Precede sensitive characters with a slash \
}
return $sCode; // Return the sanitized code
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|