Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/exercises/mysql/exercise_2/
11 filer
admin.php
back_button.php
create_table.php
dbconnection.php
delete_row.php
index.php
insert_default_values.php
insert_values.php
print_table.php
start.php
update_values.php
back_button.php
create_table.php
dbconnection.php
delete_row.php
index.php
insert_default_values.php
insert_values.php
print_table.php
start.php
update_values.php
print_table.php
58 lines UTF-8 Windows (CRLF)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Skriv ut användare</title>
<meta charset="utf-8">
<style type="text/css">
table#data {
border-collapse: collapse;
}
#data td {
padding: 8px;
border: 1px solid #686868;
}
</style>
</head>
<body>
<?php
include('back_button.php');
include ('dbconnection.php');
try {
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM users";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = [];
$stmt->execute($data);
$output = "
<table id='data'>
<caption>
<strong>Användare</strong>
</caption>
<br><br>";
while ($response = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>
<td>".htmlentities($response['firstname'])."</td>
<td>".htmlentities($response['lastname'])."</td>
<td>".htmlentities($response['username'])."</td>
<td>".htmlentities($response['password'])."</td>
<td>".htmlentities($response['role'])."</td>
<td>".htmlentities($response['last_edit'])."</td>
</tr>";
}
$output .= "</table>";
echo $output;
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;
?>
</body>
</html>