-
Notifications
You must be signed in to change notification settings - Fork 1
/
author.php
75 lines (75 loc) · 2.39 KB
/
author.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
64
65
66
67
68
69
70
71
72
73
74
75
<?php
$conn = mysqli_connect(
'localhost',
'root',
'111111',
'opentutorials');
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1><a href="index.php">WEB</a></h1>
<p><a href="index.php">topic</a></p>
<table border="1">
<tr>
<td>id</td><td>name</td><td>profile</td><td></td>
<?php
$sql = "SELECT * FROM author";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)){
$filtered = array(
'id'=>htmlspecialchars($row['id']),
'name'=>htmlspecialchars($row['name']),
'profile'=>htmlspecialchars($row['profile'])
);
?>
<tr>
<td><?=$filtered['id']?></td>
<td><?=$filtered['name']?></td>
<td><?=$filtered['profile']?></td>
<td><a href="author.php?id=<?=$filtered['id']?>">update</a></td>
<td>
<form action="process_delete_author.php" method="post" onsubmit="if(!confirm('sure?')){return false;}">
<input type="hidden" name="id" value="<?=$filtered['id']?>">
<input type="submit" value="delete">
</form>
</td>
</tr>
<?php
}
?>
</tr>
</table>
<?php
$escaped = array(
'name'=>'',
'profile'=>''
);
$label_submit = 'Create author';
$form_action = 'process_create_author.php';
$form_id = '';
if(isset($_GET['id'])){
$filtered_id = mysqli_real_escape_string($conn, $_GET['id']);
settype($filtered_id, 'integer');
$sql = "SELECT * FROM author WHERE id = {$filtered_id}";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
$escaped['name'] = htmlspecialchars($row['name']);
$escaped['profile'] = htmlspecialchars($row['profile']);
$label_submit = 'Update author';
$form_action = 'process_update_author.php';
$form_id = '<input type="hidden" name="id" value="'.$_GET['id'].'">';
}
?>
<form action="<?=$form_action?>" method="post">
<?=$form_id?>
<p><input type="text" name="name" placeholder="name" value="<?=$escaped['name']?>"></p>
<p><textarea name="profile" placeholder="profile"><?=$escaped['profile']?></textarea></p>
<p><input type="submit" value="<?=$label_submit?>"></p>
</form>
</body>
</html>