All TalkersCode Topics

Follow TalkersCode On Social Media

Alert Message In PHP

Last Updated : Jan 1, 2023

Alert Message In PHP

In this tutorial we will show you the solution of alert message in PHP, first there are many ways with help of which we are able to alert messages in php.

Alert message are like a pop up message. For example, in some webpages when we complete our registration then a message appear in which we text is you are registered successfully, etc.

We all many times see these types of messages in web also.

Step By Step Guide On Alert Message In PHP :-

Here, as we want to alert a message in php. We all know that alert message in only done through jQuery or JavaScript.

So, how we are able to alert message in php. Should we have to write JavaScript and jQuery codes here or not. How alert can be possible.

Let us answers these all the questions with help of below codes.

<!DOCTYPE html>
      <html>
        <head>
          <title> alert message in php </title>
<script src=’js/jQuery.js’>
</script>
   </head>
 <body>
 <?php
 echo "<script>
  alert('$message');
 </script>";
// another way
function alert($message) {
     echo "<script>alert('$message');</script>";
}
// Function call
alert("Welcome to this world of happiness");
?>
 </body>
      </html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
  5. Here, inside body as we can see that there we create a php tag. In which <?php is our opening tag and ?> is our closing tag.
  6. After that here inside the php tags we see that we just use echo. We all know that echo is used to print php statement of display and we can also use html and other tags inside this to display specific content. We use the same concept with jQuery. We all know that jQuery is used to display alert message using alert() function.
  7. So, we use script tag inside echo tag. To show that inside this tag there is jQuery format. Since, we use alert inside script tag to display alert message. Whereas message is written inside alert() function.
  8. In next step or say method we use the same concept but with help of functions. And to print message using alert we just call that specific function and message is provided to function as parameter.
  9. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last in conclusion, here we can say that with the help of this article we are able to understand how to alert message in php.

I hope this tutorial on alert message in PHP helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials