Open In App

How to Pop an Alert Message Box using PHP?

Last Updated : 06 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The alert message just like a pop-up window on the screen. Using this you can alert to the user with some information and message. PHP doesn't support alert message box because it is a server-side language but you can use JavaScript code within the PHP body to alert the message box on the screen.

Syntax: 

alert("Message")

Program 1: PHP program to pop up an alert box on the screen.  

PHP
<?php
// PHP program to pop an alert
// message box on the screen

// Display the alert box 
echo '<script>alert("Welcome to Geeks for Geeks")</script>';

?>

Output: 

Program 2: PHP program to pop up an alert box on the screen.  

PHP
<?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 for Geeks");

?>

Output: 

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.


Next Article

Similar Reads