Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/

bacon-egg-pizza.php
cquiz.php
create-account.php
create-account111.php
create-quiz.php
create-quiz2.php
createaccount.php
delete-quiz.php
drop-rps-tables.php
legacy-code-rps.php
legacy-index.php
login.php
logincheck.php
newpassword-verify.php
newpassword.php
potential-code.txt
quiz-db-init.php
quizhub.php
quizhub2.php
results.php
rpsaccount-ajax-user-search.php
rpsaccount.php
rpsbetting-ajax-match-finder.php
rpsbetting.php
rpsbettingleaderboard.php
rpschangepassword.php
rpschangepassword.txt
rpsgame-ajax.php
rpsgame.php
rpsgameresults.php
rpshostnewgame.php
rpshub.php
rpsleaderboard.php
rpslib.php
rpslogin.php
rpsmaininclude.php
rpsproject/
rpsusersearch.php
table-init.php
verification.php

results.php

124 lines UTF-8 Windows (CRLF)
<?php require('logincheck.php'); $userKey $_SESSION['userid'];?>

<html>
    <body>
    <h1>Quizresultat</h1>
    <h3>välkommen <?php echo $_SESSION['user']; ?></h3>
    välj quiz
    <br>
        <?php
            $sql 
"SELECT * FROM qlist";
            
$stmt $dbconn->prepare($sql);
            
$stmt->execute();
            while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
                
$quizName $res['qlname'];
                echo(
'<form action="" method="GET"><button type="submit" name="quiz" value="'.$quizName.'">'.$quizName.'</button>');
            }
        
?>
    </form>

    <?php
        
if(isset($_GET['quiz'])){
            
            
$selectedQuiz $_GET['quiz'];
            
$sql "SELECT * FROM qlist WHERE qlname='$selectedQuiz'";
            
$stmt $dbconn->prepare($sql);
            
$stmt->execute();
            while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
                
$quizID $res['listid'];
            }

            echo 
$selectedQuiz.'<br><br>';

            
$sql "SELECT * FROM quserresults WHERE quizkey='$quizID' AND userkey='$userKey'";
            
$stmt $dbconn->prepare($sql);
            
$stmt->execute();
            while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
                echo 
'<br>ditt resultat: '.$res['totscore'];
                echo 
'<br>'.$res['htmldata'];
            }
            
            if(
$_SESSION['isadmin']==1){
                echo 
"<br>-----<br>admin access<br>-----<br>
                <br>allas resultat<br>"
;

                
$ukeys = [];
                
$uscores =[];
                
$uscoreindex 0;
                
                
$sql "SELECT quserresults.userkey, quserresults.totscore, qusers.username FROM quserresults CROSS JOIN qusers ON quserresults.userkey=qusers.userid WHERE quserresults.quizkey = '$quizID' ORDER BY quserresults.totscore DESC, qusers.username ASC";
                
$stmt $dbconn->prepare($sql);
                
$stmt->execute();
                while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
                    
$uscore $res['totscore'];
                    
$ukey $res['userkey'];
                    
array_push($ukeys$ukey);
                    
array_push($uscores$uscore);
                    
$un $res['username'];

                    echo 
$un.'&nbsp'.$uscore.'<br>';
                }
                
            }

            
$scoreArray =[];
            
$sql "SELECT * FROM quserresults WHERE quizkey='$quizID'";
            
$stmt $dbconn->prepare($sql);
            
$stmt->execute();
            while(
$res $stmt->fetch(PDO::FETCH_ASSOC)){
                
array_push($scoreArray$res['totscore']);
            }
            
            
sort($scoreArray);
            
$scorecount count($scoreArray);
            
$maxscore $scoreArray[$scorecount-1];

            
$xValues = [];
            
$yValues = [];
            
$x=0;
            while(
$x<=$maxscore){
                
$tempAns 0;
                
array_push($xValues$x);
                foreach(
$scoreArray as $y){
                    if(
$y == $x){
                        
$tempAns +=1;
                    }
                }
                
$x+=1;
                
array_push($yValues$tempAns);
            }
        }

    
?>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>

<canvas id="myChart" style="width:100%;max-width:600px"></canvas>

<script>

    let xValues = <?php echo(json_encode($xValues)); ?>;
    let yValues = <?php echo(json_encode($yValues)); ?>;

const barColors = ["red"];

new Chart("myChart", {
  type: "bar",
  data: {
    labels: xValues,
    datasets: [{
      backgroundColor: barColors,
      data: yValues
    }]
  },
  options: {
    legend: {display: false},
    title: {
      display: true,
      text: "Resultat"
    }
  }
});
</script>
</body>

</html>