質問編集履歴
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,90 +38,6 @@
|
|
38
38
|
|
39
39
|
```php
|
40
40
|
|
41
|
-
form.php
|
42
|
-
|
43
|
-
<?php
|
44
|
-
|
45
|
-
session_start();
|
46
|
-
|
47
|
-
if(isset($_SESSION['id']) && $_SESSION['time'] + 3600 > time()) {
|
48
|
-
|
49
|
-
$_SESSION['time'] = time();
|
50
|
-
|
51
|
-
try {
|
52
|
-
|
53
|
-
$db = new PDO('mysql:dbname=board; host=localhost; charset=utf8', 'root', 'root');
|
54
|
-
|
55
|
-
} catch (Exception $e) {
|
56
|
-
|
57
|
-
$msg = $e->getMessage();
|
58
|
-
|
59
|
-
exit($msg);
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
$sql = 'SELECT * FROM members WHERE id=?';
|
64
|
-
|
65
|
-
$stmt = $db->prepare($sql);
|
66
|
-
|
67
|
-
$stmt->execute(array($_SESSION['id']));
|
68
|
-
|
69
|
-
$rec = $stmt->fetch();
|
70
|
-
|
71
|
-
//} else {
|
72
|
-
|
73
|
-
//header('Location : login.php');
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
$db = null
|
80
|
-
|
81
|
-
?>
|
82
|
-
|
83
|
-
<!DOCTYPE html>
|
84
|
-
|
85
|
-
<html lang="ja">
|
86
|
-
|
87
|
-
<head>
|
88
|
-
|
89
|
-
<meta charset="UTF-8">
|
90
|
-
|
91
|
-
<title>掲示板</title>
|
92
|
-
|
93
|
-
</head>
|
94
|
-
|
95
|
-
<body>
|
96
|
-
|
97
|
-
<h1>掲示板</h1>
|
98
|
-
|
99
|
-
<div style="text-align: right"><a href="logout.php">ログアウト</a></div>
|
100
|
-
|
101
|
-
<form action="contents_confirm.php" method="post">
|
102
|
-
|
103
|
-
<p><?php echo $_SESSION['name']; ?>さん、タイトルとメッセージを投稿してください</p>
|
104
|
-
|
105
|
-
タイトル<br>
|
106
|
-
|
107
|
-
<input type="text" name="title"><br>
|
108
|
-
|
109
|
-
メッセージ<br>
|
110
|
-
|
111
|
-
<textarea name="message" cols="50" rows="5"></textarea><br>
|
112
|
-
|
113
|
-
<input type="submit" value="投稿する"><br>
|
114
|
-
|
115
|
-
</form>
|
116
|
-
|
117
|
-
</body>
|
118
|
-
|
119
|
-
</html>
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
confirm.php
|
124
|
-
|
125
41
|
|
126
42
|
|
127
43
|
<?php
|
@@ -138,21 +54,7 @@
|
|
138
54
|
|
139
55
|
if($title && $message !== '') {
|
140
56
|
|
141
|
-
|
57
|
+
.....
|
142
|
-
|
143
|
-
$db = new PDO('mysql:dbname=board; host=localhost; charset=utf8', 'root', 'root');
|
144
|
-
|
145
|
-
} catch (Exception $e) {
|
146
|
-
|
147
|
-
$msg = $e->getMessage();
|
148
|
-
|
149
|
-
exit($msg);
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
$sql = 'INSERT INTO posts SET member_id=?, title=?, message=?, create_date=NOW()';
|
154
|
-
|
155
|
-
$stmt = $db->prepare($sql);
|
156
58
|
|
157
59
|
$stmt->execute(array($_SESSION['id'], $title, $message));
|
158
60
|
|
@@ -168,47 +70,7 @@
|
|
168
70
|
|
169
71
|
}
|
170
72
|
|
171
|
-
$db = null
|
172
73
|
|
173
|
-
?>
|
174
|
-
|
175
|
-
<!DOCTYPE html>
|
176
|
-
|
177
|
-
<html lang="ja">
|
178
|
-
|
179
|
-
<head>
|
180
|
-
|
181
|
-
<meta charset="UTF-8">
|
182
|
-
|
183
|
-
<title>内容確認</title>
|
184
|
-
|
185
|
-
</head>
|
186
|
-
|
187
|
-
<body>
|
188
|
-
|
189
|
-
<p> <?php foreach ($errors as $value) : ?>
|
190
|
-
|
191
|
-
<p><?php echo $value; ?></p>
|
192
|
-
|
193
|
-
<br>
|
194
|
-
|
195
|
-
<a href="contents.php"><button>戻る</button></a>
|
196
|
-
|
197
|
-
<?php endforeach; ?>
|
198
|
-
|
199
|
-
<?php if (isset($result)) : ?>
|
200
|
-
|
201
|
-
<?php echo $result; ?></p><br>
|
202
|
-
|
203
|
-
<br>
|
204
|
-
|
205
|
-
<a href="contents.php">投稿画面へ</a>
|
206
|
-
|
207
|
-
<?php endif; ?>
|
208
|
-
|
209
|
-
</body>
|
210
|
-
|
211
|
-
</html>
|
212
74
|
|
213
75
|
```
|
214
76
|
|