How to prevent duplicate posts with wp_insert_post on single.php?

try putting your script in a function and running it during an action hook. perhaps the wp_footer hook.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)