Update if post with specific title exists

First, I would use WP_Query instead of the manual DB query (and don’t tell me that’s because of performance because you’re querying 2 times the same thing). Second, you’re saving your post as draft status and querying post with status publish