Show sourcecode
The following files exists in this folder. Click to view.
public_html/exercises/databas/ovn_db1/
createtable.php
deletepost.php
index.html
insertpost.php
selectposts.php
showtable.php
updatepost.php
showtable.php
46 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Show Table</title>
</head>
<body>
<form action="index.html" method="get"><button type="submit">Tillbaka till meny</button></form>
<?php
include('../dbconnection.php');
if (!$dbconn) {
die("Connection failed: Can't connect to database.");
}
// Ouput table with all posts
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM kompisar";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = array();
$stmt->execute($data);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!$rows) {
echo "<p>Inga rader hittades. Kontrollera databas/tablens innehåll.</p>";
} else {
$output = "<table><caption>Kompisar i table:</caption>";
foreach ($rows as $res) {
$output .= "<tr>" .
"<td>" . htmlentities($res['id']) . "</td>" .
"<td>" . htmlentities($res['firstname']) . "</td>" .
"<td>" . htmlentities($res['lastname']) . "</td>" .
"<td>" . htmlentities($res['mobilenumber']) . "</td>" .
"<td>" . htmlentities($res['email']) . "</td>" .
"</tr>";
}
$output .= "</table>";
echo $output;
}
$dbconn = null;
?>
</body>
</html>