If you want to do this only in PHP, you will need to add "steps" in your script, like:

step1 (show form) -> step2 (ask validation) -> step3 (validate)

To do so, you can use sessions to keep form content, and GET parameter to track the step. Otherwise the simplest solution is to use javascript:

echo "<td><a onClick=\"javascript: return confirm('Please confirm deletion');\" href='delete.php?id=".$query2['id']."'>x</a></td><tr>"; //use double quotes for js inside php!
Answer from GHugo on Stack Overflow
🌐
Team Treehouse
teamtreehouse.com › community › how-to-create-a-confirmation-box-in-php
How to create a confirmation box in php (Example) | Treehouse Community
June 13, 2014 - //Then wherever you're running document ready or general page scripts, you'll want to echo $alert_script //scripts <?php if (isset($alert_script) { echo $alert_script; } ?> At the same time, you want to stop any additional code executing until the user selects the confirm box. You might add a variable $error = true if a validation fails and only allow the success functions to run if (!$error) { Success Function (i.e. writing to database or sending email) } Validation messages via javascript might be considered obtrusive - if the user has js turned off, how are they going to know what the error is?
🌐
SitePoint
sitepoint.com › php
A confirmation dialog box in PHP - PHP - SitePoint Forums | Web Development & Design Community
May 13, 2018 - Hi everyone, I have code where a MySQL table’s row is deleted. Before deleting I’d like a user’s confirmation whereby dialog box. Can anyone show me how to do that? Thanks
🌐
STechies
stechies.com › display-alert-message-box-dialogue-box-using-php
How to Display Alert Message Box in PHP?
<html><head> <meta charset="utf-8"> <title>JavaScript Alert Box by PHP</title> <?php function createConfirmationmbox(){ echo '<script type="text/javascript"> '; echo ' function openulr(newurl) {'; echo ' if (confirm("Are you sure you want to open new URL")) {'; echo ' document.location = newurl;'; echo ' }'; echo '}'; echo '</script>'; } ?> <?php createConfirmationmbox(); ?> </head> <body> <strong><a href="javascript:openulr('newurl.html');">Open new URL</a></strong> </body> </html>
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-pop-an-alert-message-box-using-php
How to Pop an Alert Message Box using PHP? - GeeksforGeeks
July 12, 2025 - <?php // PHP program to pop an alert // message box on the screen // Function definition function function_alert($message) { // Display the alert box echo "<script>alert('$message');</script>"; } // Function call function_alert("Welcome to Geeks ...
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
[SOLVED] PHP confirm message box - PHP Coding Help - PHP Freaks
January 19, 2009 - Hi guys, So, i'm pulling back images in a loop, and on each image i have a delete link that goes to something like: images.php?delete=1&id=28 so it will delete the image with an id of 28 from MySQL however i would like to have an "are you sure?" YesNo message box pop up. Does anyone know if t...
🌐
Stack Overflow
stackoverflow.com › questions › 39957661 › how-to-display-confirm-box-on-website-in-php
How to display confirm box on website in php
October 10, 2016 - <html> <head> <title>Are you sure?</title> <script> function areYouSure() { var res = confirm("Are you sure?"); return res; //true or false } </script> </head> <body> <form method="POST" action="action_page.php"> <!-- ...
🌐
Experts Exchange
experts-exchange.com › questions › 23091105 › How-to-Create-a-Confirmation-Box-using-PHP-and-Javascript-while-passing-back-a-usable-php-variable.html
Solved: How to Create a Confirmation Box using PHP and Javascript while passing back a usable php variable | Experts Exchange
January 17, 2008 - ?> <script language="JavaScript"> if (confirm("<? echo $msg; ?>")) { <? $result == "ok"; ?> } else { <? $result == "cancel"; ?> } </script> <? } } ?> ... We believe in human intelligence.
Find elsewhere
🌐
Simplilearn
simplilearn.com › home › resources › software development › alert in php: displaying an alert message box in php
Alert in PHP: Displaying An Alert Message Box in PHP
January 26, 2025 - Deep dive into alert in PHP tutorial and learn how to display an ⚠️ alert message box in PHP, types of pop-up boxes with examples. Start learning now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Stack Overflow
stackoverflow.com › questions › 12673034 › confirmation-message-on-user-input-in-php
javascript - Confirmation message on user input in php
August 15, 2012 - <form name="example" action="saver.php" onsubmit="return confirm('Confirmation Message');"> <!-- Inputs / Elements --> </form> Regarding your other query (Passing your Javascript result to your PHP file): If you want the value of what the user has choosen you could insert a hidden field with the status of the confirmation box.
🌐
Scaler
scaler.com › home › topics › php alert
PHP alert - Scaler Topics
April 1, 2024 - PHP offers various methods to implement alerts, such as using built-in functions like echo or print or leveraging JavaScript for more interactive and dynamic alerts. Alert dialog boxes can be used to display messages, confirmation prompts, or collect user input through prompt dialog boxes.
🌐
Stack Overflow
stackoverflow.com › questions › 43716538 › confirmation-box-in-php
confirmation box in php?
November 19, 2016 - when PHP start to execute the codes from top to bottom no way u can make any arrangements to give a PAUSE to the execution of code & take instruction from the user. ... if( isset($_GET['confirm']) && $_GET['confirm'] == "yes" ) { $curl = curl.init(); curl_opt_array($curl, array( CURLOPT_URL =>1, CURL_URL ==> "http://10.10.10.10/list/list17?ip=192.1.1.1", )) $resp = curl_exec($curl); $info =curl_getinfo($curl); $ststusCode = $info["http_code"]; curl_close($curl); if($statusCode ==200) { echo '<h1>good</h1>'; }else{ echo '<h1> Error</h1>'; } } ?> <a href="api.php?confirm=yes">YES</a> & <a href="api.php?confirm=no">NO</a>
🌐
Quora
quora.com › How-can-I-display-a-confirm-message-in-PHP-and-MySQL-using-JavaScript
How to display a confirm message in PHP and MySQL using JavaScript - Quora
Answer (1 of 2): As Marin Marinov says, your javascript is just a previous filter to a typical form submit that sends the resource id to be deleted to the server. If you want to make it using ajax, you could look at http://api.jquery.com/jquery.ajax/, I personally use it like that [code] $.ajax...
🌐
Javatpoint
javatpoint.com › php-alert
PHP alert - javatpoint
December 24, 2025 - PHP alert with examples, php file, php session, php date, php array, php form, functions, time, xml, ajax, php mysql, regex, string, oop, addslashes(), addcslashes() etc.
🌐
Stack Overflow
stackoverflow.com › questions › 44372299 › using-onclick-to-display-a-confirmation-message-within-php-html
using onclick to display a confirmation message within php/html
I like this. Thanks 2017-06-05T15:39:09.883Z+00:00 ... The code highlighting in your code snippet already shows you what's wrong: The single quote actually breaks your echo statement.
🌐
YouTube
youtube.com › watch
How to Open an alert message box using PHP - YouTube
Learn, How to open or pop up and alert message box using PHP. download source code and explore more? https://rathorji.in/p/how_to_open_an_alert_message_box_u...
Published   June 9, 2021