Posts Tagged ‘MySQL’

MySQL string escaping in PHP

December 26th, 2009 | No Comments »

Simple function to prepare user inputted data for inserting into a MySQL database. It simply checks if stripslashes() should be called, and then escapes the string. Basic, but handy.

function mysql_escape($string) {
    if (get_magic_quotes_gpc() == 1) {
        $string = stripslashes($string);
    }
    $string = mysql_real_escape_string($string);
    return $string;
}
Tags: , | Categories: Useful Stuff