Reset $wpdb->insert_id on a failed INSERT or REPLACE. See [24459] [24494].

Merges [24872] to the 3.6 branch.



git-svn-id: https://core.svn.wordpress.org/branches/3.6@24873 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fixes JavaScript error caused by [24828] which was an improper port of [24827]

See #24829


git-svn-id: https://core.svn.wordpress.org/branches/3.6@24874 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fix potential SQLi through improper use of API functions. For 3.6.


git-svn-id: https://core.svn.wordpress.org/branches/3.6@24876 1a063a9b-81f0-0310-95a4-ce76da25c4cd