1

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>
Dietrich
  • 11
  • 3

2 Answers2

1

Just a suggestion, try adding this in the <head> section of your page:

<meta charset="utf-8">
questhat23
  • 128
  • 5
  • Thanx for the replies guys, I have tried that and it has not changed anything. See the link to the screenshot below. The strange characters only show on the page in about 1 in every 5 page loads and also only on the first instance of the code that echoes something. http://postimg.org/image/txizye80p/ – Dietrich Jul 27 '15 at 12:24
0

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

Community
  • 1
  • 1
Dietrich
  • 11
  • 3