On an unrelated side note, this:
$name = stripslashes("$name");
will probably not give you the desired results. This will (more than likely) literally try to stripslashes on the text $name, rather than stripping the slashes on the actual data contained within the variable definition.
Do this instead.
$name = stripslashes($name);
You should check all of your stripslashes for this...