-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
63 lines (58 loc) · 1.61 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
59
60
61
62
63
<?php
$conn = mysqli_connect(
'localhost',
'root',
'111111',
'opentutorials');
$sql = "SELECT * FROM topic";
$result = mysqli_query($conn, $sql);
$list = '';
while($row = mysqli_fetch_array($result)) {
$escaped_title = htmlspecialchars($row['title']);
$list = $list."<li><a href=\"index.php?id={$row['id']}\">{$escaped_title}</a></li>";
}
$article = array(
'title'=>'Welcome',
'description'=>'Hello, web'
);
$update_link = '';
$delete_link = '';
$author = '';
if(isset($_GET['id'])) {
$filtered_id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT * FROM topic LEFT JOIN author ON topic.author_id = author.id WHERE topic.id={$filtered_id}";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$article['title'] = htmlspecialchars($row['title']);
$article['description'] = htmlspecialchars($row['description']);
$article['name'] = htmlspecialchars($row['name']);
$update_link = '<a href="update.php?id='.$_GET['id'].'">update</a>';
$delete_link = '
<form action="process_delete.php" method="post">
<input type="hidden" name="id" value="'.$_GET['id'].'">
<input type="submit" value="delete">
</form>
';
$author = "<p>by {$article['name']}</p>";
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1><a href="index.php">WEB</a></h1>
<a href="author.php">author</a>
<ol>
<?=$list?>
</ol>
<p><a href="create.php">create</a></p>
<?=$update_link?>
<?=$delete_link?>
<h2><?=$article['title']?></h2>
<?=$article['description']?>
<?=$author?>
</body>
</html>