質問編集履歴
5
ソースコードを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
複数の簡易掲示板を作成しています。
|
2
2
|
一つ目の掲示板はエラーもなく動作しているのですが、
|
3
|
-
二つ目の掲示板
|
3
|
+
二つ目の掲示板を作成したら動作はしているのですが、下記のエラーがあります。
|
4
4
|
一つ目の掲示板はうまく動作しているのに二つ目は何故エラーになるのか分からないです。
|
5
5
|
コードにまだ慣れていなくどこに記載をしたら良いのか分からないです。
|
6
6
|
宜しくお願いします。
|
7
7
|
|
8
8
|
エラー:Array ([0] => 00000[1] =>[2] => )
|
9
9
|
|
10
|
+

|
10
11
|
|
12
|
+
|
13
|
+
|
11
14
|
【コード追記・修正箇所】
|
12
15
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
13
16
|
} catch (PDOException $e) {
|
@@ -77,6 +80,8 @@
|
|
77
80
|
|
78
81
|
(fot.html)
|
79
82
|
```PHP
|
83
|
+
|
84
|
+
<!-- ここから掲示板1 -->
|
80
85
|
<?php
|
81
86
|
// 1ページに表示されるコメントの数
|
82
87
|
$num = 3;
|
@@ -97,6 +102,98 @@
|
|
97
102
|
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
98
103
|
//プリペアドステートメントを作成
|
99
104
|
$stmt = $db->prepare(
|
105
|
+
"SELECT * FROM bbs ORDER BY date DESC LIMIT
|
106
|
+
:page, :num"
|
107
|
+
);
|
108
|
+
//パラメータを割り当て
|
109
|
+
$page = $page * $num;
|
110
|
+
$stmt->bindParam(':page', $page, PDO::PARAM_INT);
|
111
|
+
$stmt->bindParam(':num', $num, PDO::PARAM_INT);
|
112
|
+
//クエリの実行
|
113
|
+
$stmt->execute();
|
114
|
+
} catch(PDOException $e){
|
115
|
+
echo "エラー:" . $e->getMessage(). "\n" . $e->getTraceAsString();
|
116
|
+
}
|
117
|
+
|
118
|
+
?>
|
119
|
+
<div id="nav-drawer"><!-- ハンバーガー -->
|
120
|
+
<input id="nav-input" type="checkbox" class="nav-unshown">
|
121
|
+
<label id="nav-open" for="nav-input">
|
122
|
+
<img src="img/a.jpg" class="fot">
|
123
|
+
</label><span></span>
|
124
|
+
<label class="nav-unshown" id="nav-close" for="nav-input"></label>
|
125
|
+
<div id="nav-content">
|
126
|
+
<div align="center">
|
127
|
+
<img src="img/a.jpg" width="550" height="400">
|
128
|
+
<br>コメント入力
|
129
|
+
|
130
|
+
<?php
|
131
|
+
while ($row = $stmt->fetch()):
|
132
|
+
$title = $row['title'] ? $row['title'] : '(無題)';
|
133
|
+
?>
|
134
|
+
<p>名前:<?php echo $row['name'] ?></p>
|
135
|
+
<p>タイトル:<?php echo $title ?></p>
|
136
|
+
<p><?php echo nl2br($row['body'], false) ?></p>
|
137
|
+
<p><?php echo $row['date'] ?></p>
|
138
|
+
<?php
|
139
|
+
endwhile;
|
140
|
+
|
141
|
+
//ページ数の表示
|
142
|
+
try {
|
143
|
+
//プリペアドステートメント作成
|
144
|
+
$stmt = $db->prepare("SELECT COUNT(*) FROM bbs");
|
145
|
+
//クエリ
|
146
|
+
$stmt->execute();
|
147
|
+
} catch (PDOException $e){
|
148
|
+
echo "エラー:" . $e->getMessage(). "\n" . $e->getTraceAsString();
|
149
|
+
}
|
150
|
+
|
151
|
+
//コメントの件数を取得
|
152
|
+
$comments = $stmt->fetchColumn();
|
153
|
+
//ページ数を計算
|
154
|
+
$max_page = ceil($comments / $num);
|
155
|
+
echo '<p>';
|
156
|
+
for ($i = 1; $i <= $max_page; $i++){
|
157
|
+
echo '<a href="fot.php?page=' . $i . '">' . $i .
|
158
|
+
'</a> ';
|
159
|
+
}
|
160
|
+
echo '</p>';
|
161
|
+
?>
|
162
|
+
</span>
|
163
|
+
|
164
|
+
<span class="form">
|
165
|
+
<form action="write.php" method="post">
|
166
|
+
<p>名前:<input type="text" name="name"></p>
|
167
|
+
<p>タイトル:<input type="text" name="title"></p>
|
168
|
+
<textarea name="body"></textarea>
|
169
|
+
<p><input type="submit" value="書き込む"> <input type="reset" value="リセット"></p>
|
170
|
+
</form>
|
171
|
+
</span><!-- form -->
|
172
|
+
</div><!-- nav-content終了 -->
|
173
|
+
</div><!-- ハンバーガー -->
|
174
|
+
|
175
|
+
<!-- ここから掲示板2 -->
|
176
|
+
|
177
|
+
<?php
|
178
|
+
// 1ページに表示されるコメントの数
|
179
|
+
$num = 3;
|
180
|
+
|
181
|
+
//データベースに接続
|
182
|
+
$dsn = 'mysql:host=localhost;dbname=db11;charset=utf8';
|
183
|
+
$user = 'db11user';
|
184
|
+
$password = '1111'; //DBパスワード
|
185
|
+
|
186
|
+
//ページ数が指定されているとき
|
187
|
+
$page = 0;
|
188
|
+
if (isset($_GET['page']) && $_GET['page'] > 0) {
|
189
|
+
$page = intval($_GET['page']) -1;
|
190
|
+
}
|
191
|
+
|
192
|
+
try {
|
193
|
+
$db = new PDO($dsn, $user, $password);
|
194
|
+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
195
|
+
//プリペアドステートメントを作成
|
196
|
+
$stmt = $db->prepare(
|
100
197
|
"SELECT * FROM bbs1 ORDER BY date DESC LIMIT
|
101
198
|
:page, :num"
|
102
199
|
);
|
@@ -108,18 +205,20 @@
|
|
108
205
|
//クエリの実行
|
109
206
|
$stmt->execute();
|
110
207
|
} catch(PDOException $e) {
|
111
|
-
|
208
|
+
echo "エラー:" . $e->getMessage(). "\n" . $e->getTraceAsString();
|
112
209
|
}
|
113
|
-
?>
|
210
|
+
?>
|
211
|
+
|
114
|
-
|
212
|
+
<div id="nav-drawer1"><!-- ハンバーガー -->
|
115
|
-
|
213
|
+
<input id="nav-input1" type="checkbox" class="nav-unshown1">
|
116
214
|
<label id="nav-open1" for="nav-input1">
|
117
|
-
<img src="
|
215
|
+
<img src="img/a.jpg" class="fot">
|
118
|
-
</label><span></span>
|
216
|
+
</label><span></span>
|
119
217
|
<label class="nav-unshown1" id="nav-close1" for="nav-input1"></label>
|
120
218
|
<div id="nav-content1">
|
121
|
-
<img src="
|
219
|
+
<img src="img/a.jpg" width="550" height="400">
|
122
|
-
|
220
|
+
<br>コメント入力
|
221
|
+
|
123
222
|
<?php
|
124
223
|
while ($row = $stmt->fetch()):
|
125
224
|
$title = $row['title'] ? $row['title'] : '(無題)';
|
@@ -138,7 +237,7 @@
|
|
138
237
|
//クエリ
|
139
238
|
$stmt->execute();
|
140
239
|
} catch (PDOException $e){
|
141
|
-
echo "エラー:" . $e->getMessage();
|
240
|
+
echo "エラー:" . $e->getMessage(). "\n" . $e->getTraceAsString();
|
142
241
|
}
|
143
242
|
|
144
243
|
//コメントの件数を取得
|
@@ -152,8 +251,11 @@
|
|
152
251
|
}
|
153
252
|
echo '</p>';
|
154
253
|
?>
|
155
|
-
</span>
|
254
|
+
</span>
|
255
|
+
|
256
|
+
|
156
|
-
<p class="name1">この料理へのコメントはこちらから!!</p>
|
257
|
+
<p class="name1">この料理へのコメントはこちらから!!</p>
|
258
|
+
|
157
259
|
<span class="form">
|
158
260
|
<form action="write1.php" method="post">
|
159
261
|
<p>名前:<input type="text" name="name"></p>
|
@@ -162,5 +264,8 @@
|
|
162
264
|
<p><input type="submit" value="書き込む"> <input type="reset" value="リセット"></p>
|
163
265
|
</form>
|
164
266
|
</span><!-- form -->
|
267
|
+
</div><!-- nav-content終了 -->
|
268
|
+
</div><!-- ハンバーガー -->
|
269
|
+
|
165
270
|
|
166
271
|
```
|
4
コード修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
複数の簡易掲示板を作成しています。
|
2
2
|
一つ目の掲示板はエラーもなく動作しているのですが、
|
3
3
|
二つ目の掲示板は動作はしているのですが、下記のエラーがあります。
|
4
|
+
一つ目の掲示板はうまく動作しているのに二つ目は何故エラーになるのか分からないです。
|
4
5
|
コードにまだ慣れていなくどこに記載をしたら良いのか分からないです。
|
5
6
|
宜しくお願いします。
|
6
7
|
|
7
8
|
エラー:Array ([0] => 00000[1] =>[2] => )
|
8
9
|
|
10
|
+
|
11
|
+
【コード追記・修正箇所】
|
12
|
+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
13
|
+
} catch (PDOException $e) {
|
14
|
+
die ('エラー:' . $e->getMessage() . "\n" . $e->getTraceAsString());
|
15
|
+
}
|
16
|
+
|
17
|
+
$stmt = $db->prepare("
|
18
|
+
INSERT INTO bbs1 (name, title, body, date )
|
19
|
+
VALUES (?, ?, ?, now() )"
|
20
|
+
);
|
21
|
+
|
9
|
-
write1.php
|
22
|
+
(write1.php)
|
10
23
|
```PHP
|
11
24
|
|
12
25
|
<?php
|
@@ -33,33 +46,121 @@
|
|
33
46
|
try {
|
34
47
|
$db = new PDO($dsn, $user, $password);
|
35
48
|
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
49
|
+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
36
|
-
|
50
|
+
} catch (PDOException $e) {
|
51
|
+
die ('エラー:' . $e->getMessage() . "\n" . $e->getTraceAsString());
|
52
|
+
}
|
53
|
+
|
37
54
|
$stmt = $db->prepare("
|
38
55
|
INSERT INTO bbs1 (name, title, body, date )
|
39
|
-
VALUES (
|
56
|
+
VALUES (?, ?, ?, now() )"
|
40
57
|
);
|
41
58
|
|
42
59
|
//パラメータを割り当て
|
43
|
-
$stmt->bindParam(
|
60
|
+
$stmt->bindParam(1, $name, PDO::PARAM_STR);
|
44
|
-
$stmt->bindParam(
|
61
|
+
$stmt->bindParam(2, $title, PDO::PARAM_STR);
|
45
|
-
$stmt->bindParam(
|
62
|
+
$stmt->bindParam(3, $body, PDO::PARAM_STR);
|
46
63
|
|
47
|
-
$stmt = $db->prepare("
|
48
|
-
INSERT INTO bbs1 (name, title, body, date )
|
49
|
-
VALUES (name, title, body, now() )"
|
50
|
-
|
51
|
-
|
52
64
|
//クエリの実行
|
53
65
|
$stmt->execute();
|
54
66
|
|
55
67
|
//fot.phpに戻る
|
56
68
|
header('Location: fot.php');
|
57
69
|
exit();
|
70
|
+
|
71
|
+
?>
|
72
|
+
```
|
73
|
+
|
74
|
+
DB一覧。
|
75
|
+

|
76
|
+
|
77
|
+
|
78
|
+
(fot.html)
|
79
|
+
```PHP
|
80
|
+
<?php
|
81
|
+
// 1ページに表示されるコメントの数
|
82
|
+
$num = 3;
|
83
|
+
|
84
|
+
//データベースに接続
|
85
|
+
$dsn = 'mysql:host=localhost;dbname=db11;charset=utf8';
|
86
|
+
$user = 'db11user';
|
87
|
+
$password = '1111'; //DBパスワード
|
88
|
+
|
89
|
+
//ページ数が指定されているとき
|
90
|
+
$page = 0;
|
91
|
+
if (isset($_GET['page']) && $_GET['page'] > 0) {
|
92
|
+
$page = intval($_GET['page']) -1;
|
93
|
+
}
|
94
|
+
|
95
|
+
try {
|
96
|
+
$db = new PDO($dsn, $user, $password);
|
97
|
+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
98
|
+
//プリペアドステートメントを作成
|
99
|
+
$stmt = $db->prepare(
|
100
|
+
"SELECT * FROM bbs1 ORDER BY date DESC LIMIT
|
101
|
+
:page, :num"
|
102
|
+
);
|
103
|
+
//パラメータを割り当て
|
104
|
+
$page = $page * $num;
|
105
|
+
print_r($db->errorInfo());
|
106
|
+
$stmt->bindParam(':page', $page, PDO::PARAM_INT);
|
107
|
+
$stmt->bindParam(':num', $num, PDO::PARAM_INT);
|
108
|
+
//クエリの実行
|
109
|
+
$stmt->execute();
|
58
110
|
} catch(PDOException $e) {
|
59
|
-
die ('エラー:' . $e->getMessage());
|
111
|
+
die ('エラー:' . $e->getMessage() . "\n" . $e->getTraceAsString());
|
60
112
|
}
|
113
|
+
?>
|
114
|
+
<div id="nav-drawer1"><!-- ハンバーガー -->
|
115
|
+
<input id="nav-input1" type="checkbox" class="nav-unshown1">
|
116
|
+
<label id="nav-open1" for="nav-input1">
|
117
|
+
<img src="test.png" width="150" height="150">
|
118
|
+
</label><span></span>
|
119
|
+
<label class="nav-unshown1" id="nav-close1" for="nav-input1"></label>
|
120
|
+
<div id="nav-content1">
|
121
|
+
<img src="test.png" width="550" height="400">
|
122
|
+
|
123
|
+
<?php
|
124
|
+
while ($row = $stmt->fetch()):
|
125
|
+
$title = $row['title'] ? $row['title'] : '(無題)';
|
61
126
|
?>
|
127
|
+
<p>名前:<?php echo $row['name'] ?></p>
|
128
|
+
<p>タイトル:<?php echo $title ?></p>
|
129
|
+
<p><?php echo nl2br($row['body'], false) ?></p>
|
130
|
+
<p><?php echo $row['date'] ?></p>
|
131
|
+
<?php
|
132
|
+
endwhile;
|
133
|
+
|
134
|
+
//ページ数の表示
|
62
|
-
|
135
|
+
try {
|
136
|
+
//プリペアドステートメント作成
|
137
|
+
$stmt = $db->prepare("SELECT COUNT(*) FROM bbs1");
|
138
|
+
//クエリ
|
139
|
+
$stmt->execute();
|
140
|
+
} catch (PDOException $e){
|
141
|
+
echo "エラー:" . $e->getMessage();
|
142
|
+
}
|
143
|
+
|
144
|
+
//コメントの件数を取得
|
145
|
+
$comments = $stmt->fetchColumn();
|
146
|
+
//ページ数を計算
|
147
|
+
$max_page = ceil($comments / $num);
|
148
|
+
echo '<p>';
|
149
|
+
for ($i = 1; $i <= $max_page; $i++){
|
150
|
+
echo '<a href="fot.php?page=' . $i . '">' . $i .
|
151
|
+
'</a> ';
|
152
|
+
}
|
153
|
+
echo '</p>';
|
154
|
+
?>
|
155
|
+
</span>
|
156
|
+
<p class="name1">この料理へのコメントはこちらから!!</p>
|
157
|
+
<span class="form">
|
158
|
+
<form action="write1.php" method="post">
|
159
|
+
<p>名前:<input type="text" name="name"></p>
|
160
|
+
<p>タイトル:<input type="text" name="title"></p>
|
161
|
+
<textarea name="body"></textarea>
|
162
|
+
<p><input type="submit" value="書き込む"> <input type="reset" value="リセット"></p>
|
163
|
+
</form>
|
164
|
+
</span><!-- form -->
|
63
165
|
|
64
|
-
|
166
|
+
```
|
65
|
-

|
3
情報修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,14 +15,13 @@
|
|
15
15
|
error_reporting(E_ALL);
|
16
16
|
ini_set('display_errors', '1');
|
17
17
|
|
18
|
-
|
19
18
|
// データの受け取り
|
20
|
-
$
|
19
|
+
$name = $_POST['name'];
|
21
|
-
$
|
20
|
+
$title = $_POST['title'];
|
22
|
-
$
|
21
|
+
$body = $_POST['body'];
|
23
22
|
|
24
23
|
//必須項目チェック(名前か本文が空ではないか?)
|
25
|
-
if ($
|
24
|
+
if ($name == '' || $body == ''){
|
26
25
|
header('Location: fot.php'); // fot.phpへ移動
|
27
26
|
exit(); //終了
|
28
27
|
}
|
@@ -36,15 +35,20 @@
|
|
36
35
|
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
37
36
|
//プリペアドステートメント作成
|
38
37
|
$stmt = $db->prepare("
|
39
|
-
INSERT INTO bbs1 (
|
38
|
+
INSERT INTO bbs1 (name, title, body, date )
|
40
|
-
VALUES (:
|
39
|
+
VALUES (:name, :title, :body, now() )"
|
41
40
|
);
|
42
41
|
|
43
42
|
//パラメータを割り当て
|
44
|
-
$stmt->bindParam(':
|
43
|
+
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
|
45
|
-
$stmt->bindParam(':
|
44
|
+
$stmt->bindParam(':title', $title, PDO::PARAM_STR);
|
46
|
-
$stmt->bindParam(':
|
45
|
+
$stmt->bindParam(':body', $body, PDO::PARAM_STR);
|
47
46
|
|
47
|
+
$stmt = $db->prepare("
|
48
|
+
INSERT INTO bbs1 (name, title, body, date )
|
49
|
+
VALUES (name, title, body, now() )"
|
50
|
+
|
51
|
+
|
48
52
|
//クエリの実行
|
49
53
|
$stmt->execute();
|
50
54
|
|
@@ -57,100 +61,5 @@
|
|
57
61
|
?>
|
58
62
|
```
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
fot.php
|
63
|
-
```PHP
|
64
|
-
<?php
|
65
|
-
// 1ページに表示されるコメントの数
|
66
|
-
$num = 3;
|
67
|
-
|
68
|
-
//データベースに接続
|
69
|
-
$dsn = 'mysql:host=localhost;dbname=db11;charset=utf8';
|
70
|
-
$user = 'db11user';
|
71
|
-
$password = '1111'; //DBパスワード
|
72
|
-
|
73
|
-
//ページ数が指定されているとき
|
74
|
-
$page = 0;
|
75
|
-
if (isset($_GET['page']) && $_GET['page'] > 0) {
|
76
|
-
$page = intval($_GET['page']) -1;
|
77
|
-
}
|
78
|
-
|
79
|
-
try {
|
80
|
-
$db = new PDO($dsn, $user, $password);
|
81
|
-
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
82
|
-
//プリペアドステートメントを作成
|
83
|
-
$stmt = $db->prepare(
|
84
|
-
"SELECT * FROM bbs1 ORDER BY date1 DESC LIMIT
|
85
|
-
:page, :num"
|
86
|
-
);
|
87
|
-
//パラメータを割り当て
|
88
|
-
$page = $page * $num;
|
89
|
-
print_r($db->errorInfo());
|
90
|
-
$stmt->bindParam(':page', $page, PDO::PARAM_INT);
|
91
|
-
$stmt->bindParam(':num', $num, PDO::PARAM_INT);
|
92
|
-
//クエリの実行
|
93
|
-
$stmt->execute();
|
94
|
-
} catch(PDOException $e){
|
95
|
-
echo "エラー:" . $e->getMessage();
|
96
|
-
}
|
97
|
-
|
98
|
-
?>
|
99
|
-
<div id="nav-drawer1"><!-- ハンバーガー -->
|
100
|
-
<input id="nav-input1" type="checkbox" class="nav-unshown1">
|
101
|
-
<label id="nav-open1" for="nav-input1">
|
102
|
-
<img src="test.png" alt="test" width="150" height="150">
|
103
|
-
</label><span></span>
|
104
|
-
<label class="nav-unshown1" id="nav-close1" for="nav-input1"></label>
|
105
|
-
<div id="nav-content1">
|
106
|
-
<img src="test.png" alt="test" width="550" height="400">
|
107
|
-
<?php
|
108
|
-
while ($row = $stmt->fetch()):
|
109
|
-
$title = $row['title1'] ? $row['title1'] : '(無題)';
|
110
|
-
?>
|
111
|
-
<p>名前:<?php echo $row['name1'] ?></p>
|
112
|
-
<p>タイトル:<?php echo $title ?></p>
|
113
|
-
<p><?php echo nl2br($row['body1'], false) ?></p>
|
114
|
-
<p><?php echo $row['date1'] ?></p>
|
115
|
-
<?php
|
116
|
-
endwhile;
|
117
|
-
|
118
|
-
//ページ数の表示
|
119
|
-
try {
|
120
|
-
//プリペアドステートメント作成
|
121
|
-
$stmt = $db->prepare("SELECT COUNT(*) FROM bbs1");
|
122
|
-
//クエリ
|
123
|
-
$stmt->execute();
|
124
|
-
} catch (PDOException $e){
|
125
|
-
echo "エラー:" . $e->getMessage();
|
126
|
-
}
|
127
|
-
|
128
|
-
//コメントの件数を取得
|
129
|
-
$comments = $stmt->fetchColumn();
|
130
|
-
//ページ数を計算
|
131
|
-
$max_page = ceil($comments / $num);
|
132
|
-
echo '<p>';
|
133
|
-
for ($i = 1; $i <= $max_page; $i++){
|
134
|
-
echo '<a href="fot.php?page=' . $i . '">' . $i .
|
135
|
-
'</a> ';
|
136
|
-
}
|
137
|
-
echo '</p>';
|
138
|
-
?>
|
139
|
-
</span>
|
140
|
-
|
141
|
-
<p class="name1">この料理へのコメントはこちらから!!</p>
|
142
|
-
|
143
|
-
<span class="form">
|
144
|
-
<form action="write1.php" method="post">
|
145
|
-
<p>名前:<input type="text" name="name1"></p>
|
146
|
-
<p>タイトル:<input type="text" name="title1"></p>
|
147
|
-
<textarea name="body1"></textarea>
|
148
|
-
<p><input type="submit" value="書き込む"> <input type="reset" value="リセット"></p>
|
149
|
-
</form>
|
150
|
-
</span><!-- form -->
|
151
|
-
</div><!-- nav-content終了 -->
|
152
|
-
</div><!-- ハンバーガー -->
|
153
|
-
```
|
154
|
-
|
155
64
|
DB一覧。
|
156
65
|

|
2
情報修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
簡易掲示板を作成しています。
|
1
|
+
複数の簡易掲示板を作成しています。
|
2
|
+
一つ目の掲示板はエラーもなく動作しているのですが、
|
2
|
-
|
3
|
+
二つ目の掲示板は動作はしているのですが、下記のエラーがあります。
|
3
4
|
コードにまだ慣れていなくどこに記載をしたら良いのか分からないです。
|
4
5
|
宜しくお願いします。
|
5
6
|
|
@@ -149,4 +150,7 @@
|
|
149
150
|
</span><!-- form -->
|
150
151
|
</div><!-- nav-content終了 -->
|
151
152
|
</div><!-- ハンバーガー -->
|
152
|
-
```
|
153
|
+
```
|
154
|
+
|
155
|
+
DB一覧。
|
156
|
+

|
1
文言修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
簡易掲示板を作成しています。
|
2
2
|
PHPの動作はうまくいっているのですが、下記のエラーが発生しております。
|
3
|
-
|
3
|
+
コードにまだ慣れていなくどこに記載をしたら良いのか分からないです。
|
4
4
|
宜しくお願いします。
|
5
5
|
|
6
6
|
エラー:Array ([0] => 00000[1] =>[2] => )
|
7
7
|
|
8
|
+
write1.php
|
8
9
|
```PHP
|
9
10
|
|
10
11
|
<?php
|
@@ -53,4 +54,99 @@
|
|
53
54
|
die ('エラー:' . $e->getMessage());
|
54
55
|
}
|
55
56
|
?>
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
fot.php
|
62
|
+
```PHP
|
63
|
+
<?php
|
64
|
+
// 1ページに表示されるコメントの数
|
65
|
+
$num = 3;
|
66
|
+
|
67
|
+
//データベースに接続
|
68
|
+
$dsn = 'mysql:host=localhost;dbname=db11;charset=utf8';
|
69
|
+
$user = 'db11user';
|
70
|
+
$password = '1111'; //DBパスワード
|
71
|
+
|
72
|
+
//ページ数が指定されているとき
|
73
|
+
$page = 0;
|
74
|
+
if (isset($_GET['page']) && $_GET['page'] > 0) {
|
75
|
+
$page = intval($_GET['page']) -1;
|
76
|
+
}
|
77
|
+
|
78
|
+
try {
|
79
|
+
$db = new PDO($dsn, $user, $password);
|
80
|
+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
81
|
+
//プリペアドステートメントを作成
|
82
|
+
$stmt = $db->prepare(
|
83
|
+
"SELECT * FROM bbs1 ORDER BY date1 DESC LIMIT
|
84
|
+
:page, :num"
|
85
|
+
);
|
86
|
+
//パラメータを割り当て
|
87
|
+
$page = $page * $num;
|
88
|
+
print_r($db->errorInfo());
|
89
|
+
$stmt->bindParam(':page', $page, PDO::PARAM_INT);
|
90
|
+
$stmt->bindParam(':num', $num, PDO::PARAM_INT);
|
91
|
+
//クエリの実行
|
92
|
+
$stmt->execute();
|
93
|
+
} catch(PDOException $e){
|
94
|
+
echo "エラー:" . $e->getMessage();
|
95
|
+
}
|
96
|
+
|
97
|
+
?>
|
98
|
+
<div id="nav-drawer1"><!-- ハンバーガー -->
|
99
|
+
<input id="nav-input1" type="checkbox" class="nav-unshown1">
|
100
|
+
<label id="nav-open1" for="nav-input1">
|
101
|
+
<img src="test.png" alt="test" width="150" height="150">
|
102
|
+
</label><span></span>
|
103
|
+
<label class="nav-unshown1" id="nav-close1" for="nav-input1"></label>
|
104
|
+
<div id="nav-content1">
|
105
|
+
<img src="test.png" alt="test" width="550" height="400">
|
106
|
+
<?php
|
107
|
+
while ($row = $stmt->fetch()):
|
108
|
+
$title = $row['title1'] ? $row['title1'] : '(無題)';
|
109
|
+
?>
|
110
|
+
<p>名前:<?php echo $row['name1'] ?></p>
|
111
|
+
<p>タイトル:<?php echo $title ?></p>
|
112
|
+
<p><?php echo nl2br($row['body1'], false) ?></p>
|
113
|
+
<p><?php echo $row['date1'] ?></p>
|
114
|
+
<?php
|
115
|
+
endwhile;
|
116
|
+
|
117
|
+
//ページ数の表示
|
118
|
+
try {
|
119
|
+
//プリペアドステートメント作成
|
120
|
+
$stmt = $db->prepare("SELECT COUNT(*) FROM bbs1");
|
121
|
+
//クエリ
|
122
|
+
$stmt->execute();
|
123
|
+
} catch (PDOException $e){
|
124
|
+
echo "エラー:" . $e->getMessage();
|
125
|
+
}
|
126
|
+
|
127
|
+
//コメントの件数を取得
|
128
|
+
$comments = $stmt->fetchColumn();
|
129
|
+
//ページ数を計算
|
130
|
+
$max_page = ceil($comments / $num);
|
131
|
+
echo '<p>';
|
132
|
+
for ($i = 1; $i <= $max_page; $i++){
|
133
|
+
echo '<a href="fot.php?page=' . $i . '">' . $i .
|
134
|
+
'</a> ';
|
135
|
+
}
|
136
|
+
echo '</p>';
|
137
|
+
?>
|
138
|
+
</span>
|
139
|
+
|
140
|
+
<p class="name1">この料理へのコメントはこちらから!!</p>
|
141
|
+
|
142
|
+
<span class="form">
|
143
|
+
<form action="write1.php" method="post">
|
144
|
+
<p>名前:<input type="text" name="name1"></p>
|
145
|
+
<p>タイトル:<input type="text" name="title1"></p>
|
146
|
+
<textarea name="body1"></textarea>
|
147
|
+
<p><input type="submit" value="書き込む"> <input type="reset" value="リセット"></p>
|
148
|
+
</form>
|
149
|
+
</span><!-- form -->
|
150
|
+
</div><!-- nav-content終了 -->
|
151
|
+
</div><!-- ハンバーガー -->
|
56
152
|
```
|