How does the magic_quotes_gpc setting affect the storage and retrieval of data in a MySQL database using PHP?

The magic_quotes_gpc setting in PHP automatically adds slashes to incoming data from forms, which can lead to double escaping and corrupt data when storing or retrieving it in a MySQL database. To solve this issue, you should disable the magic_quotes_gpc setting in your PHP configuration.

// Disable magic_quotes_gpc setting
if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value) {
        $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
        return $value;
    }

    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}