It is a notification system. The code below is working fine. When I click on the notification (
Php file that generates notifications:
<ul class="dropdown-menu">
<li class="header">Você tem <?php echo $cont; ?> notificações</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
<!-- Notificações -->
<?php
foreach(variavel as variavel):
(...)
print '
<li>
<a onclick="sendData()" href="#">
<i class="'.$icone.'"></i> '.$nome.'
<input type="hidden" name="id" id="id" value="'.$id.'">
</a>
</li>';
endforeach;
?>
</ul>
</li>
<li class="footer"><a href="notif.php">Ver todas</a></li>
</ul>
jquery / ajax function:
<script>
function sendData()
{
var idn = $('#id').val();
$.ajax({
type:"POST",
url:"upd.php",
data: { id: idn },
cache: false,
});
}
</script>
Update.php file:
(...)
$id = $_POST['id'];
$sql = "UPDATE notif SET status = 1 WHERE id = :id";
(...)