How to use Toastr Alerts in PHP?

Apr 07, 2022 . Admin

Hello dev,

I am going to explain you How to use Toastr Alerts in PHP?. You will learn How To Use Toastr In Php?

This article will give you simple example of Creating Real Time Notification System in PHP and AJAX. We will use get simple How can I show a Toast notification on form submission.

I will give you simple Example of How to use Toastr Alerts in PHP?.

So, let's see bellow solution:

<!DOCTYPE html>  
    <title>How to use Toastr Alerts in PHP?</title>
    <link href="" rel="stylesheet">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
        position: absolute; 
        top: 10px; 
        right: 10px;
<body class="bg-dark">  
    <div class="container mt-5 pt-5" >
        <div class="row">
            <div class="col-md-12">
                <div class="card mt-3">
                    <div class="card-header text-center bg-danger text-white">
                        <h1>How to use Toastr Alerts in PHP?</h1>
                    <div class="card-body">
                        <form id="submit_form">
                            <div class="mb-3"> 
                                <label>Email : </label>  
                                <input type="email" name="email" id="email" class="form-control" />  
                            <div class="mb-3">
                                <label>Message : </label>  
                                <textarea name="message" id="message" class="form-control" rows="5" ></textarea>  
                            <div class="d-flex justify-content-center">
                                <input type="button" name="submit" id="submit" class="btn btn-primary" value="Submit" />  
        <div class="toast" id="myToast" data-bs-autohide="true">
            <div class="toast-header">
                <strong class="me-auto"><i class="bi-bell-fill"></i>notification</strong>
                <small>1 sec ago</small>
                <button type="button" class="btn-close" data-bs-dismiss="toast"></button>
            <div class="toast-body">
                <p id="error_message"></p>
            var email = $('#email').val();  
            var message = $('#message').val();  
            if(email == '' || message == ''){  
                $('#error_message').html("All Fields are required");
                    data:{email:email, message:message},  
    $servername = "localhost";
    $username = "root";
    $password = "root";
    $dbname = "aatman";

    $conn = new mysqli($servername,$username,$password,$dbname);

      die ('connection faild:'.$conn->connect_error);

    $email = $_POST['email'];
    $message = $_POST['message'];
    $sql = "INSERT INTO users (email,message)VALUES('$email','$message')"; 

    if ($conn->query($sql)===TRUE) {
        echo "message sent successfully";     
        echo "Error: ".$sql."<br>".$conn->error;

It will help you...