I use this for any data that is provided by user input that will go into a query...

PHP Code:
  function escape_data($param1$param2) {
    if(
ini_get('magic_quotes_gpc')) {
      
$data stripslashes($param1);
    } else {
      
$data $param1;
    }
    
    return 
mysql_real_escape_string($data$param2);
  } 
You pass the data you want to 'escape' to the first argument, and the connection to the database to the 2nd argument, which is whatever is returned from the mysql_connect() function.

(I more-or-less got this from the book I learned PHP from, so if there is a better way then I am open to suggestions...)