I can't seem to figure out why the button that is generated increments the vote_count values of every post in the database rather than just the one it is generated with. Does anyone know a way to make my code so that it will only increment the vote_count value in the same row as that specific post. I am using MySQL.
Here is my code
echo "<button class='button' id='press_me' >Press Me</button>";
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<script>
$(function (){
$('#press_me').click(function(){
var request = $.ajax({
type: "POST",
url: "server_code_increment.php"
});
request.done(function( msg ) {
alert('Success');
return;
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
});
});
</script>
Here is server_code_increment.php
<?php
// Connection to database
$connection=mysqli_connect("localhost","root","","phplikes");
// Check connection
if (mysqli_connect_errno())
{
echo 'NOT_OK';
//echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Increasing the current value with 1
$query = mysqli_query($connection,"UPDATE meme_vote SET vote_count = (like_count + 1)
");
mysqli_close($connection);
echo 'OK'; ?>