I have this "Read More" link:
echo '<p>'.$readNewsResult['content'].'<a class="test" href="#fancybox'.$readNewsResult['id_news'].'">Read More</a></p>';
When I click in this link, my goal is to update views column of my news table.
So I have a jQuery where Im passing id of my news, and it is working fine, when I click on "Read more" link I get an alert message saying: "action=update&update=311", where 311 is id of my clicked news.
My jQuery until now:
$(function(){
var read = $('.news');
read.on('click','.test',function(){
var updateid = $(this).attr("id");
var updatedata = "action=update&update="+updateid;
alert(updatedata);
$.ajax({
data: updatedata,
beforesend: '',
error: '',
success: function(updateR)
{
alert(updateR);
}
});
});
});
But now with php, Im trying to get update action and id, and do update on my news table, but its not working, because it seems that I never enter in my switch condition.
I tried to give some "echos" inside my case, and when I click on my "Read more" link my echo never appears.
Do you see where might be the problem??
$action = $_POST['action'];
switch($action)
{
case 'update':
$id = $_POST['id'];
$updateViews = $pdo->prepare("UPDATE news SET views=:views WHERE id=:id");
$updateViews->bindValue(':views', '1');
$updateViews->bindValue(':id', $id);
$updateViews->execute();
break;
}