All the interaction with the user that you are trying to develop is developed only on the client's side, in your browser, using a programming language different from PHP, which is executed only once on the server.
You must understand that the server generates an HTML page using the PHP programming language and that the HTML is interpreted (after it has been generated and sent to the client) in a browser and it will not be related to the server until the user returns to click on a link or send a form (or use some XHR asynchronous function).
Everything on the client side
resultado = confirm('Registro repetido!!!');
if (resultado == true) {
document.write("Selecciono SI");
} else {
document.write("Selecciono NO");
}
You will see that everything works in local, without the need of a PHP server that receives the answer.
Sending the response via a form to a PHP
resultado = confirm('Registro repetido!!!');
document.formu.resultado.value = resultado;
document.formu.submit();
<form action="receptor.php" method="post" name="formu">
<input type="hidden" name="resultado"/>
</form>
In this case, when you reply you try to send the form to receptor.php
, and since it does not exist on the stackoverflow server it sends you an error, but if you run it on your server and have that PHP script, you will receive the result in it.