-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetcomments.bak
77 lines (58 loc) · 1.57 KB
/
getcomments.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<?php
require_once 'dbconfig.php';
//define variables
try {
//connect to batabase
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
//echo "Connected to database $dbname at $host successfully. <br>";
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = ("SELECT `name`,
`comment`,
`entered`
FROM `comment`
");
$result = $pdo->query($sql);
// echo '<h2>Comments</h2>';
// while($row = $result->fetch(PDO::FETCH_ASSOC)) {
$comment = $row['comment'];
$name = htmlspecialchars($row['name']);
$entered = htmlspecialchars(date('d F Y H:i:s',strtotime($row['entered'])));
// echo 'Comment: '.$comment. '<br />'.
// 'Posted By: '. '<b>'. $name. '</b><br /> '.
// 'Posted On: '. $entered. '<br /> <br />';
// echo '<hr>';
}
//connection error
catch (PDOException $pe) {
die("Could not connect to the database $dbname :" . $pe->getMessage());
}
$pdo->close();
?>
<head></head>
<body>
<div id="container">
<h1>Comments</h1>
<table width ="100%" border ="1">
<thead>
<tr>
<td>Name</td>
<td>Comment</td>
<td>Entered</td>
</tr>
</thead>
<tbody>
<?php while ($row = $result->FetchALL(PDO::FETCH_ASSOC)) {
echo
"<tr>
<td>".$row['comment']." </td>
<td>".$row['name']." </td>
<td>".$row['entered']." </td>
</tr>\n";
}
?>
</tbody>
</table>
<body>
</html>