I'm trying to implement a push notification in php, but i can´t have any value from there.
The code needs to increase the number of notifications when the expire_date is within a month to expire.
i have this for now: php file fetch.php
<?php
$con = mysqli_connect("localhost","root","");
if(!$con){
echo"Not connect to Server";
}
if(!mysqli_select_db($con,'newusers')){
echo 'Database not select';
}
$count=0;
$DataAuditoria=_$POST['DataAuditoria'];
$dateToday = date("Y-m-d");
$query = "SELECT auditorias FROM Clientes";
$result = mysqli_query($con, $query);
$output = echo '';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$DataAuditoria1=$row["auditorias"];
if($DataAuditoria1 != "" && $DataAuditoria1 != NULL){
$DataAuditoria_notificacao = date("Y-m-d", strtotime(date("Y-m-d", strtotime($DataAuditoria1)) . " -1 months"));
$diasquefaltam= (int)((strtotime($DataAuditoria1) - strtotime($dateToday))/(60*60*24));
if( $diasquefaltam<=30 && $diasquefaltam>=0){
$output .= echo "{$row['Nome']}";
$output.= echo "{$diasquefaltam}";
$count++;
}
}
}
else{
$output .= echo "No Notifications for today";
}
$data = array(
'notification' => $output,
'unseen_notification' => $count,
);
echo json_encode($data);
}
?>
html: form to upload data
<div class="modal fade" id="AuditoriaAdd" role="dialog">
<div class="modal-dialog">
<div class="modal-footer bg-3">
<form role="form" method="post" id="comment_form" action="Teste_apagar.php">
<input type="hidden" name="idClienteAuditoria" class="form-control" placeholder="" >
<div class="col-sm-12">
<h5>Enter Subject</h5>
<input type="date" name="DataAuditoriaAdd" id="DataAuditoriaAdd" class="form-control">
</div>
<button type="submit" class="btn btn-success btn-block" name="post" id="post" class="btn btn-info" value="Post">Add</button>
</form>
</div>
</div>
</div>
script:
$(document).ready(function(){
// updating the view with notifications using ajax
function load_unseen_notification(view = '')
{
$.ajax({
url:"fetch.php",
method:"POST",
data:{view:view},
dataType:"json",
success:function(data)
{
$('.dropdown-menu').html(data.notification);
if(data.unseen_notification > 0)
{
$('.count').html(data.unseen_notification);
}
}
});
}
load_unseen_notification();
// submit form and get new records
$('#comment_form').on('submit', function(event){
event.preventDefault();
if($('#DataAuditoriaAdd').val() != '')
{
var form_data = $(this).serialize();
$.ajax({
url:"InsertBD.php",
method:"POST",
data:form_data,
success:function(data)
{
$('#comment_form')[0].reset();
load_unseen_notification();
}
});
}
else
{
alert("Both Fields are Required");
}
});
// load new notifications
$(document).on('click', '.dropdown-toggle', function(){
$('.count').html('');
load_unseen_notification('yes');
});
setInterval(function(){
load_unseen_notification();;
}, 5000);
});
none of this seems to work, can anyone help me?