質問編集履歴

4

追加

2018/10/09 02:58

投稿

2929man
2929man

スコア10

test CHANGED
File without changes
test CHANGED
@@ -163,3 +163,63 @@
163
163
  ?>
164
164
 
165
165
  ```
166
+
167
+
168
+
169
+ ```<?php
170
+
171
+ require_once '\MAMP\db_config.php';
172
+
173
+ $soft_name = $_POST['soft_name'];
174
+
175
+ $impressions = $_POST['impressions'];
176
+
177
+ $category = (int) $_POST['category'];
178
+
179
+ $difficulty = (int) $_POST['difficulty'];
180
+
181
+ $score = (int) $_POST['score'];
182
+
183
+ try {
184
+
185
+ include_once '\MAMP\error_check.php';
186
+
187
+ $dbh = new PDO('mysql:host=localhost;dbname=db1;charset=utf8', $user, $pass);
188
+
189
+ $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
190
+
191
+ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
192
+
193
+ $sql = "INSERT INTO nostalgia (soft_name, category, difficulty, score, impressions) VALUES (?, ?, ?, ?, ?)";
194
+
195
+ $stmt = $dbh->prepare($sql);
196
+
197
+ $stmt->bindValue(1, $soft_name, PDO::PARAM_STR);
198
+
199
+ $stmt->bindValue(2, $category, PDO::PARAM_INT);
200
+
201
+ $stmt->bindValue(3, $difficulty, PDO::PARAM_INT);
202
+
203
+ $stmt->bindValue(4, $score, PDO::PARAM_INT);
204
+
205
+ $stmt->bindValue(5, $impressions, PDO::PARAM_STR);
206
+
207
+ $stmt->execute();
208
+
209
+ $dbh = null;
210
+
211
+ echo "感想の登録が完了しました。<br>";
212
+
213
+ echo "<a href='index.php'>トップページへ戻る</a>";
214
+
215
+ } catch (Exception $e) {
216
+
217
+ echo "エラー発生: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . "<br>";
218
+
219
+ die();
220
+
221
+ }
222
+
223
+
224
+
225
+ ```

3

追加

2018/10/09 02:58

投稿

2929man
2929man

スコア10

test CHANGED
File without changes
test CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
  HTMLのform部分です
58
58
 
59
- コード
59
+
60
60
 
61
61
  ```
62
62
 
@@ -80,9 +80,15 @@
80
80
 
81
81
  </form>
82
82
 
83
+ ```
84
+
85
+
86
+
83
87
 
84
88
 
85
89
  ~phpの取得部分~
90
+
91
+ ```
86
92
 
87
93
 
88
94
 
@@ -152,8 +158,8 @@
152
158
 
153
159
  }
154
160
 
155
-
156
-
157
-
161
+
158
162
 
159
163
  ?>
164
+
165
+ ```

2

追加依頼

2018/10/09 02:56

投稿

2929man
2929man

スコア10

test CHANGED
File without changes
test CHANGED
@@ -40,16 +40,120 @@
40
40
 
41
41
 
42
42
 
43
- echo "<br>";
44
43
 
45
- if ($_POST['difficulty'] === '1') echo "簡単";
46
44
 
47
-        if ($_POST['difficulty'] === '2') echo "普通";
48
-
49
- if ($_POST['difficulty'] === '3') echo "難しい";
50
-
51
- echo "<br>";
45
+ ブラウザは、chromeです。MAMPを使っています。
52
46
 
53
47
 
54
48
 
49
+ ~以下追加2~
50
+
51
+
52
+
55
- ブラウザはchrome、MAMP使っています。
53
+ ちなみに市販のテキストを写し自分で内容変更しようとしています。
54
+
55
+
56
+
57
+ HTMLのform部分です
58
+
59
+ コード
60
+
61
+ ```
62
+
63
+ <form method="post" action="add.php">
64
+
65
+
66
+
67
+ 難易度:
68
+
69
+ <input type="radio" name="difficulty" value="1">簡単
70
+
71
+ <input type="radio" name="difficulty" value="2" checked>普通
72
+
73
+ <input type="radio" name="difficulty" value="3">難しい
74
+
75
+ <br>
76
+
77
+
78
+
79
+ <input type="submit" value="送信">
80
+
81
+ </form>
82
+
83
+
84
+
85
+ ~phpの取得部分~
86
+
87
+
88
+
89
+ <?php
90
+
91
+ require_once '\MAMP\db_config.php';
92
+
93
+ try {
94
+
95
+ $dbh = new PDO('mysql:host=localhost;dbname=db1;charset=utf8', $user, $pass);
96
+
97
+ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
98
+
99
+ $sql = "SELECT * FROM nostalgia";
100
+
101
+ $stmt = $dbh->query($sql);
102
+
103
+ $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+ echo "<table>\n";
112
+
113
+ echo "<tr>\n";
114
+
115
+ echo "<th>ソフトタイトル</th><th>評価点</th><th>難易度</th>\n";
116
+
117
+ echo "</tr>\n";
118
+
119
+ foreach ($result as $row) {
120
+
121
+ echo "<tr>\n";
122
+
123
+ echo "<td>" . htmlspecialchars($row['soft_name'],ENT_QUOTES,'UTF-8') . "</td>\n";
124
+
125
+ echo "<td>" . htmlspecialchars($row['score'],ENT_QUOTES,'UTF-8') . "</td>\n";
126
+
127
+ echo "<td>" . htmlspecialchars($row['difficulty'],ENT_QUOTES,'UTF-8') . "</td>\n";
128
+
129
+ echo "<td>\n";
130
+
131
+ echo "<a href=detail.php?id=" . htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8') . ">詳細</a>\n";
132
+
133
+ echo "|<a href=edit.php?id=" . htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8') . ">変更</a>\n";
134
+
135
+ echo "|<a href=delete.php?id=" . htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8') . ">削除</a>\n";
136
+
137
+ echo "</td>\n";
138
+
139
+ echo "</tr>\n";
140
+
141
+ }
142
+
143
+ echo "</table>\n";
144
+
145
+ $dbh = null;
146
+
147
+ } catch (Exception $e) {
148
+
149
+ echo "エラー発生: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . "<br>";
150
+
151
+ die();
152
+
153
+ }
154
+
155
+
156
+
157
+
158
+
159
+ ?>

1

PGの追記

2018/10/09 02:31

投稿

2929man
2929man

スコア10

test CHANGED
File without changes
test CHANGED
@@ -33,3 +33,23 @@
33
33
 
34
34
 
35
35
  どなたかご教授願います。
36
+
37
+
38
+
39
+ ~以下追記~
40
+
41
+
42
+
43
+ echo "<br>";
44
+
45
+ if ($_POST['difficulty'] === '1') echo "簡単";
46
+
47
+        if ($_POST['difficulty'] === '2') echo "普通";
48
+
49
+ if ($_POST['difficulty'] === '3') echo "難しい";
50
+
51
+ echo "<br>";
52
+
53
+
54
+
55
+ ブラウザは、chrome、MAMPを使っています。