-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.php
58 lines (46 loc) · 1.29 KB
/
index.php
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
<?php
include 'config.php';
if (isset($_POST['post_comment'])) {
$name = $_POST['name'];
$message = $_POST['message'];
$sql = "INSERT INTO demo (name, message)
VALUES ('$name', '$message')";
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Comment System PHP | National Coding</title>
</head>
<body>
<div class="wrapper">
<form action="" method="post" class="form">
<input type="text" class="name" name="name" placeholder="Name">
<br>
<textarea name="message" cols="30" rows="10" class="message" placeholder="Message"></textarea>
<br>
<button type="submit" class="btn" name="post_comment">Post Comment</button>
</form>
</div>
<div class="content">
<?php
$sql = "SELECT * FROM demo";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<h3><?php echo $row['name']; ?></h3>
<p><?php echo $row['message']; ?></p>
<?php } } ?>
</div>
</body>
</html>