There is a numeric variable(variable name score below) which is a javascript variable. I have a php code inside which the javascript blocks have been used. Now what I want to do is: I want to get the actual value of score variable into my php code, and then save it into DB through the php code. I have tried the below code to do so. But I don't see any value coming into the $score variable declared in php and I simple see some error in the web page. Below the code there is a screenshot that explains the error message.
function check() {
var score = 0;
var wrong_answers="";
for(count = 0; count < 2; count++){
var e = document.getElementById(count + 1);
var answer_selected = e.options[e.selectedIndex].value;
if(e.selectedIndex === parseInt(allAnswer[count])){
score = score + 1;
}
else{
wrong_answers = wrong_answers +" "+ (count+1).toString();
}
}
<?php
$score = "<script>document.write(score)</script>";
$query4 = "UPDATE USER_RESULT SET SCORE = '$score' WHERE START_TIME =
'$startTime'";
$query_run4 = mysqli_query($conn,$query4);
?>
}