Reputation: 11
The program gets 5 variables from 2 database tables and compares them to each other. Each correct match increments a correct variable.
I should be getting a number like "100%" but instead get "�%" and "?%" etc. or just random characters.
See below extract from the HTML page
<!DOCTYPE html>
<html xmlns="w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<?php
$user = $_SESSION['currentUser'];
$answerCheck1 = mysqli_query($conn,"SELECT * FROM tutorial_exam");
$answerRowCheck1 = mysqli_fetch_array($answerCheck1);
$answerCheck2 = mysqli_query($conn,"SELECT * FROM tutorials_test WHERE user_id='$user'");
$answerRowCheck2 = mysqli_fetch_array($answerCheck2);
$answerCheckT = mysqli_query($conn,"SELECT * FROM tutorials WHERE user_id='$user'");
$answerRowCheckT = mysqli_fetch_array($answerCheckT);
$total = $answerRowCheckT['exam'];
if($total > 0){$total = $total ."%";}else{$total = '';}
$counter1 = 1;
$correct1 = 0;
$userAnswer1 = '';
$databaseAnswer1 = '';
while($counter1 <= 5)
{
$index1 = 'q'.$counter1;
$userAnswer1 = $answerRowCheck2[$index1];
$databaseAnswer1 = $answerRowCheck1[$index1];
if($userAnswer1 == $databaseAnswer1)
{
$correct1 = $correct1 + 1;
//$correct = $answerRow[$counter];
}
$counter1 = $counter1 + 1;
}
$mark1 = $correct1 / 5 * 100;
$mark1 = round($mark1,0);
echo $mark1 . "%";
?>
</body>
</html>
Upvotes: 1
Views: 78
Reputation: 11
We run our system from memory sticks with Server2Go, and what seems to have fixed it is updating the PHP version on the server2Go systems.
We found out how to do that in another Stack Overflow thread: Other answer link
Upvotes: 0
Reputation: 128
Just a suggestion, try adding this in the <head>
section of your page:
<meta charset="utf-8">
Upvotes: 1