aboutsummaryrefslogtreecommitdiff
blob: e645517b473802d521b588b2157f7f9f4867a5ae (plain)
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
<?php
	class MyDB extends SQLite3 {
      function __construct() {
         $this->open('comments.db');
      }
   }

	if (isset($_POST['user'], $_POST['comment'])) {
		$user = $_POST['user'];
		$comment = $_POST['comment'];

		$db = new MyDB();

		$sql = 'INSERT INTO Comments VALUES(\'' . $user . '\',\'' . $comment . '\')';
		$ret = $db->exec($sql);
		$db->close();
	}

	echo '<!DOCTYPE HTML><html><head><title>Comments</title>' .
	   	 '<meta charset="utf-8"></head><body><h1>Comments</h1>';

	$db = new MyDB();

	$sql = 'SELECT * FROM Comments';
	$ret = $db->query($sql);
	while ($row = $ret->fetchArray(SQLITE3_ASSOC))
		echo '<p><b>' . $row['user'] . '</b> says:<br>' . $row['comment'] . '</p>';

	$db->close();

	echo '<h2>Add comment</h1><form action="index.php" method="post">' .
		 '<input type="text" name="user" placeholder="User name"><br>' .
		 '<input type="text" name="comment" placeholder="Comment"><br>' .
		 '<input type="submit" value="Add"><br>' .
		 '</form></body></html>';
?>