After clicking on submit, a record is entered in the database, but if you refresh the page, the post is duplicated. At first, I made a script with a redirect to the same page and an alert, but only the alert with the message worked, but the redirect did not occur. Then I tried to redirect through onclick, but for some reason, it was necessary to click a second time after the data were recorded so that the redirect occurred. I looked for solutions, but they either did not work or were too complex for my understanding. How to solve?
Submission
<input type="submit" value="отправить" onclick="window.open('news.php','_self');" /> php
<?php $title=$_POST['title']; $textarea=$_POST['textarea']; $img=$_POST['img']; $db = new PDO ('mysql:dbname=posting; host=localhost',"admin","1234"); $sql="insert into `news` (title,textarea,img) values (:title,:textarea,:img)"; $sth=$db->prepare($sql); $sth->bindValue(':title', $title); $sth->bindValue(':textarea', $textarea); $sth->bindValue(':img', $img); $sth->execute(); ?>