It seems to work well. But you need to add/modify some code.
For prevent SQL Injection
$query = mysqli_query($con, "SELECT score,credits FROM gebruikers WHERE leerlingennummer = '".$_SESSION['leerlingennummer']."'");
should be
$query = mysqli_query($con, "SELECT score,credits FROM gebruikers WHERE leerlingennummer = '".addslashes($_SESSION['leerlingennummer'])."'");
- $_SESSION['leerlingennummer'] can be blanked. Review your code.
Add update query
if(mysqli_num_rows($query) == 1)
{
$row = mysqli_fetch_array($query);
//get the current score and credits
$score = $row['score'];
$credits = $row['credits'];
$score = 'succes';
mysqli_query($con, "update gebruikers set `score` = '".addslashes($_POST['finalscore'])."', `credits` = '".addslashes($_POST['finalcredits'])."' where leerlingennummer = '".addslashes($_SESSION['leerlingennummer'])."'");
}
This code will modify score in mysql to 'finalscore', credits in mysql to 'finalcredits'.
Than, ajax alert will be 'succes'. If you want to be a score before update, you can do like this:
if(mysqli_num_rows($query) == 1)
{
$row = mysqli_fetch_array($query);
//get the current score and credits
$score = $row['score'];
$credits = $row['credits'];
mysqli_query($con, "update gebruikers set `score` = '".addslashes($_POST['finalscore'])."', `credits` = '".addslashes($_POST['finalcredits'])."' where leerlingennummer = '".addslashes($_SESSION['leerlingennummer'])."'");
}