Pass a user-inputted variable to this function in order to prevent SQL injection. Example:
mysqlquery("INSERT INTO table VALUES('" . sqlsanitize($_POST["variable") . "')");
Instead of:
mysqlquery("INSERT INTO table VALUES('" . $POST["variable"] . "'");
/* 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 Notes: Author: engel <[email protected]> */ function sql_sanitize( $sCode ) { } else { // If PHP version < 4.3.0 } return $sCode; // Return the sanitized code }
Comments
Subscribe to comments
You need to login to post a comment.

Helpful code, though I would just place addslashes($text) on any input field. Then always have stripslashes($text) when you withdrawl that information, simple easy code since you'll have to do strip the slashes anyway
addslashes() is no good for preventing SQL injection - it is vulnerable to character encoding trickery.