The most likely issue is that you have magic_quotes enabled on one server, but not the other.
Either disable magic_quotes or change to the code:
$example = stripslashes($_POST['example']); //undoes the magic_quotes
$escaped_string = mysql_real_escape_string($example); //escapes it properly.
A less likely scenario may occur if you have 2 connections to 2 different database server
mysql_real_escape_string
works different depending on the connection that you have open.
If you have multiple servers and thus multiple connections, you need to run the escaping function once per connection.
Example
$example = "a'b";
$connectionA = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$connectionB = mysql_connect('remotehost', 'mysql_user', 'mysql_password');
$escapedstringA = mysql_real_escape_string($example, $connectionA);
$escapedstringB = mysql_real_escape_string($example, $connectionB);
If you leave out the connection parameter in the call to mysql_real_escape_string
both escapedstrings will be escaped using the default encoding of remotehost, which is incorrect.
This code may work incorrect:
$example = "a'b";
$connectionA = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$connectionB = mysql_connect('remotehost', 'mysql_user', 'mysql_password');
$escapedstringA = mysql_real_escape_string($example); //uses remotehost's encoding
$escapedstringB = mysql_real_escape_string($example);