Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/databaser/ovn_2/

admin.php
forminclude.php
index.php
welcome.php

welcome.php

63 lines UTF-8 Windows (CRLF)
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Välkommen</title>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <?php
    session_start
();

    try {
        include(
"../dbconnection.php");
        
$sql "SELECT * from users WHERE username=? and pass=?";
        
$info = array($_SESSION["username"], $_SESSION["pass"]);

        
$stmt $dbconn->prepare($sql);
        
$stmt->execute($info);
        
$user $stmt->fetch(PDO::FETCH_ASSOC);

        if (!
$user){
            
// Skicka tillbaka om ej inloggad
            
header("Location: index.php");
        } else{
            
// Annars kör på

            
$sql "SELECT * FROM kompisar";
            
$info $dbconn->query($sql);
            echo (
"<table>
  <tr>
    <th>ID</th>
    <th>FÖRNAMN</th>
    <th>EFTERNAMN</th>
    <th>MOBILNR</th>
    <th>MEJL</th>
  </tr>"
);
            while (
$rad $info->fetch(PDO::FETCH_ASSOC)) {
                echo (
"<tr>
    <td>" 
$rad["id"] . "</td>
    <td>" 
$rad["f_namn"] . "</td>
    <td>" 
$rad["e_namn"] . "</td>
    <td>" 
$rad["mobil"] . "</td>
    <td>" 
$rad["mejl"] . "</td>
    </tr>
    "
);
            }
            echo (
"</table>");
        }
    } catch (
PDOException $e) {
        echo (
$e->getMessage());
    }
    
?>
</body>

</html>