Check out
mysql_real_escape_string which can be used to escape input so it can be safely inserted into the database.
Or move to using the new
mysqli library in PHP5 for connecting to MySQL. You can then use
mysqli_prepare and
mysqli_stmt_bind_param. You don't need to bother escaping the input then as it is handled for you.
Ben