How to Display Alert Message Box in PHP?

The alert box can used for show special message. If you want to show a message after any event like warning message, success message or other any messages. you can use alert box.

PHP does not have the ability to display an alert message box because it is a server-side language, but to display an alert message box you can use the javascript code within the PHP file. Given below give some code you can use and display a Javascript alert message box in PHP.

Example 1


<?php 
// Display the alert box  
echo '<script>alert("Your Data send Successfuly")</script>'; 
?>

Example 2

In this example when you submit form and you want to check user_name if user_name blank then show alert message (Plese Enter User Name) otherwise user_name not blank then alert message show Successfully Form Submit.

<?php 
if(isset($_POST['submit']))
{
	if($_POST['user_name']==""){
		echo '<script>alert("Plese Enter User Name")</script>'; 
	}
	else{
		echo '<script>alert("Successfuly Form Submit")</script>'; 	
	}
}
?>
<form action="" method="POST">
User Name
<input type="text" name="user_name">	
<input type="submit" name="submit">
</form>

Leave a Reply

Your email address will not be published. Required fields are marked *