How to notify when new record inserted in sql database in php?

Today, We want to share with you php notification alert when new record is inserted.In this post we will show you php notification popup, hear for notification in php demo we will give you demo and example for implement.In this post, we will learn about
Build Push Notification System with PHP & MySQL
with an example.

notification alert in php mysql

how to build jquery messages notification with php and mysql?

update Query

$sql = "update alerting_list set is_active = 'read'";
       $response = $conn->query($sql);
       $row = $response->fetch_assoc();
       $count = $response->num_rows;
       echo $count;
       $conn->close();

php form insert to database and give notification

index.php

<script>

$(document).ready(function(){

// updating the view with alertings using ajax

function display_botify_unseen_toast(view = '')

{

 $.ajax({

  url:"fetch.php",
  method:"POST",
  data:{view:view},
  dataType:"json",
  success:function(data)

  {

   $('.dropdown-menu').html(data.alerting);

   if(data.unseen_alerting > 0)
   {
    $('.count').html(data.unseen_alerting);
   }

  }

 });

}

display_botify_unseen_toast();

// submit form and get new records

$('#discusstion_form').on('submit', function(event){
 event.preventDefault();

 if($('#head_title').val() != '' && $('#discusstion').val() != '')

 {

  var form_data = $(this).serialize();

  $.ajax({

   url:"insert.php",
   method:"POST",
   data:form_data,
   success:function(data)

   {

    $('#discusstion_form')[0].reset();
    display_botify_unseen_toast();

   }

  });

 }

 else

 {
  alert("Both Fields are Required");
 }

});

// load new alertings

$(document).on('click', '.dropdown-toggle', function(){

 $('.count').html('');

 display_botify_unseen_toast('yes');

});

setInterval(function(){

 display_botify_unseen_toast();;

}, 5000);

});

</script>

Database


--
-- Database: `all_brands`
--

-- --------------------------------------------------------

--
-- Table structure for table `discusstions`
--

CREATE TABLE IF NOT EXISTS `discusstions` (
  `discusstion_id` int(11) NOT NULL,
  `discusstion_head_title` varchar(250) NOT NULL,
  `discusstion_text` text NOT NULL,
  `discusstion_is_active` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `discusstions`
--
ALTER TABLE `discusstions`
  ADD PRIMARY KEY (`discusstion_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `discusstions`
--
ALTER TABLE `discusstions`
  MODIFY `discusstion_id` int(11) NOT NULL AUTO_INCREMENT;

final code

index.php

<!DOCTYPE html>
<html>
 <head>
  <title>Facebook Style Header Notification using PHP Ajax Bootstrap - www.pakainfo.com</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 </head>
 <body>
  <br /><br />
  <div class="container">
   <nav class="navbar navbar-inverse">
    <div class="container-fluid">
     <div class="navbar-header">
      <a class="navbar-brand" href="#">Pakainfo Tutorial</a>
     </div>
     <ul class="nav navbar-nav navbar-right">
      <li class="dropdown">
       <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="label label-pill label-danger count" style="border-radius:10px;"></span> <span class="glyphicon glyphicon-envelope" style="font-size:18px;"></span></a>
       <ul class="dropdown-menu"></ul>
      </li>
     </ul>
    </div>
   </nav>
   <br />
   <h2 align="center">Simple Facebook Style Header Notification using PHP Ajax Bootstrap</h2>
   <br />
   <form method="post" id="discusstion_form">
    <div class="form-group">
     <label>Give Any Subject</label>
     <input type="text" name="head_title" id="head_title" class="form-control">
    </div>
    <div class="form-group">
     <label>Give Any Comment</label>
     <textarea name="discusstion" id="discusstion" class="form-control" rows="5"></textarea>
    </div>
    <div class="form-group">
     <input type="submit" name="post" id="post" class="btn btn-info" value="Post" />
    </div>
   </form>
   
  </div>
 </body>
</html>

<script>
$(document).ready(function(){
 
 function display_botify_unseen_toast(view = '')
 {
  $.ajax({
   url:"fetch.php",
   method:"POST",
   data:{view:view},
   dataType:"json",
   success:function(data)
   {
    $('.dropdown-menu').html(data.alerting);
    if(data.unseen_alerting > 0)
    {
     $('.count').html(data.unseen_alerting);
    }
   }
  });
 }
 
 display_botify_unseen_toast();
 
 $('#discusstion_form').on('submit', function(event){
  event.preventDefault();
  if($('#head_title').val() != '' && $('#discusstion').val() != '')
  {
   var form_data = $(this).serialize();
   $.ajax({
    url:"insert.php",
    method:"POST",
    data:form_data,
    success:function(data)
    {
     $('#discusstion_form')[0].reset();
     display_botify_unseen_toast();
    }
   });
  }
  else
  {
   alert("Both All Fields are Required");
  }
 });
 
 $(document).on('click', '.dropdown-toggle', function(){
  $('.count').html('');
  display_botify_unseen_toast('yes');
 });
 
 setInterval(function(){ 
  display_botify_unseen_toast();; 
 }, 5000);
 
});
</script>

I hope you get an idea about real time notification in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.