Hopefully I'm not duplicating this question, but I wasn't able to find the solution to the issue I am having.
I have a set of buttons, that are populated from a mySQL database. When the user clicks on ONE of the buttons, I want it to add 10 to the current value of the cell 'score' in that table where the id of the button equals the table row.
I really don't know where I'm going wrong, here.
HTML:
<button class="addPoints" data-id="person01"><span>Person01</span></button>
<button class="addPoints" data-id="person02"><span>Person02</span></button>
<button class="addPoints" data-id="person03"><span>Person03</span></button>
<button class="addPoints" data-id="person04"><span>Person04</span></button>
JS:
$(".addPoints").on('click', function(){
var $id = $( this ).data( 'id' );
console.log($id);
$.ajax({
type: "POST",
cache: false,
async: true,
url: "addPoints.php",
data: {class: $id},
success: function (data) {},
error: function(xhr, ajaxOptions, thrownError){
console.log(xhr.status);
console.log(thrownError);
}
})
});
PHP:
require "config.php";
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$class=$_POST["class"];
$sql = "UPDATE roster SET score = score + '10' WHERE `class` = ".$class;
$conn->close();
Every row in my mySQL Database "roster" has the following columns:
id, class, name, score
I'm using the same config.php to populate the buttons with their data-id and the text, so I've ruled out that it is an issue with that file. when I go to the php page 'addPoints.php', I get this error:
Notice: Undefined index: class in addPoints.php