This is my first time asking a question here.
So I have this PHP script
if($_POST['vote']){
$id = $_POST['id'];
$vote = $_POST['vote'];
$sql = "INSERT INTO question_votes ('question_id', 'user_id', 'vote', 'date') VALUES( '$id', '$log', '$vote', now())";
$query = $pdo->prepare($sql);
$query->execute();
}
Using this code
<script>
$function((){
$('.vote').click(function(){
var id = $(this).attr("id"); // cache $this
var vote = $(this).data("action");
$.ajax({
url: 'ajaxvote.php',
type: 'POST',
data: {id:id, vote:vote}
});
});
});
</script>
When I run the code it won't insert the data in the database. By the way i'm just a student and this is my first time in website development.