Q:

How do I keep quotations in variable used with PHP string

I am using a custom php query by submitting a custom search form.  Everything works great except for if a string calls a name like O'Reilly, the search will come up with no results for O\'Reilly instead of O'Reilly.  I am using the following to call the variable:
$fullname=trim($_REQUEST["fullname"]);

and this is my php header 
 header("Location: http://example.com/results?patientid=$patientid&fullname=$fullname&date=$date");

That will redirect to the search results page where I have the following code for the fullname:
             $patientid=trim($_REQUEST["patientid"]);
             $fullname=trim($_REQUEST["fullname"]);
             $date=trim($_REQUEST["date"]);

Then I echo that and it comes up O/'Reilly with the slash in it and no results. 
Should be O'Reilly

A:

If Magic Quotes is On It automatically escapes incoming data to the PHP script.  This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.  When on, all ' (single-quote), " (double quote), \ (backslash) and NULL characters are escaped with a backslash automatically.  magic_quotes_gpc Affects HTTP Request data (GET, POST, and COOKIE).  Cannot be set at runtime, and defaults to on in PHP.