Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/quiz/

adminlogin.php
createtables.php
createtest.php
dbconnection.php
index.php
kundsida.php
result.php
test.php

result.php

76 lines UTF-8 Windows (CRLF)
<?php
error_reporting
(-1); // Report all type of errors
ini_set('display_errors'1); // Display all errors 
ini_set('output_buffering'0); // Do not buffer outputs, write directly
include('dbconnection.php');
session_start();
$warningMsg "";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    table{
        border: 1px black solid;
    }
    td{
        width: 100px;
    }
    tr{
        width: 100px;
    }
    th{
        width: 100px;
        text-align: center;
        background-color: grey;
    }
    
</style>
</head>
<body>
<nav>
        <a href="index.php">Login</a> <br>
        <a href="result.php">Resultat</a> <br>
        <a href="kundsida.php">Kundsida</a> <br>
        <a href="adminlogin.php">Admin</a>
    </nav>
<?php
try{
    
$sql "SELECT * FROM testresults
    ORDER BY testid, amountcorrect"
;
    
$stmt $dbconn->prepare($sql);
    
$data = array();
    
$stmt->execute($data);
    
$output "<h1>Tester!</h1><table>
    <tr>
    <th> Test </th>
    <th> Userid </th> 
    <th> Antal rätt </th> 
    <th> Datum för Test </th> 
    </tr>
    "
;
    while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
        
$output .= "<tr>".
            
"<td>".htmlentities($res['testid'])."</td>".
            
"<td>".htmlentities($res['userid'])."</td>".
            
"<td>".htmlentities($res['amountcorrect'])."</td>".
            
"<td>".htmlentities($res['test_date'])."</td>".
        
"</tr>";
    }
    
$output .= "</table>";
    echo 
"$output";
}
catch(
PDOException $e)
{
    echo 
$sql "<br />" $e->getMessage();
}

$dbconn null;

?>
</html>
</body>
</html>