質問編集履歴

5

コード変更

2020/10/26 13:20

投稿

ayaaya_ininin
ayaaya_ininin

スコア0

test CHANGED
File without changes
test CHANGED
@@ -158,21 +158,21 @@
158
158
 
159
159
  <?php
160
160
 
161
- $user = "○○";
161
+ $user = "、、";
162
-
162
+
163
- $pass = "○○";
163
+ $pass = ”、、";
164
-
165
-
166
-
164
+
165
+
166
+
167
- $recipe_name = filter_input(INPUT_POST, 'recipe_name');
167
+ $recipe_name = $_POST['recipe_name'];
168
-
168
+
169
- $howto = filter_input(INPUT_POST, 'howto');
169
+ $howto = $_POST['howto'];
170
-
170
+
171
- $category = filter_input(INPUT_POST, 'category');
171
+ $category = (int) $_POST['category'];
172
-
172
+
173
- $difficulty = filter_input(INPUT_POST, 'difficulty');
173
+ $difficulty = (int) $_POST['difficulty'];
174
-
174
+
175
- $budget = filter_input(INPUT_POST, 'budget');
175
+ $budget = (int) $_POST['budget'];
176
176
 
177
177
  try{
178
178
 
@@ -186,8 +186,6 @@
186
186
 
187
187
  $dph->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
188
188
 
189
- //whereは、どこを更新する??という意味!!
190
-
191
189
  $sql = "UPDATE recipes SET recipe_name = ?, category = ?, difficulty = ?, budget = ?, howto = ?, WHERE id = ?";
192
190
 
193
191
  $stmt = $dph->prepare($sql);

4

ユーザー名変更

2020/10/26 13:19

投稿

ayaaya_ininin
ayaaya_ininin

スコア0

test CHANGED
File without changes
test CHANGED
@@ -158,9 +158,9 @@
158
158
 
159
159
  <?php
160
160
 
161
- $user = "yamauchi";
161
+ $user = "○○";
162
-
162
+
163
- $pass = "@ij6GW)t2hrJQd2";
163
+ $pass = "○○";
164
164
 
165
165
 
166
166
 

3

updateファイル追加

2020/10/26 13:14

投稿

ayaaya_ininin
ayaaya_ininin

スコア0

test CHANGED
File without changes
test CHANGED
@@ -152,6 +152,80 @@
152
152
 
153
153
 
154
154
 
155
+ ```PHP
156
+
157
+
158
+
159
+ <?php
160
+
161
+ $user = "yamauchi";
162
+
163
+ $pass = "@ij6GW)t2hrJQd2";
164
+
165
+
166
+
167
+ $recipe_name = filter_input(INPUT_POST, 'recipe_name');
168
+
169
+ $howto = filter_input(INPUT_POST, 'howto');
170
+
171
+ $category = filter_input(INPUT_POST, 'category');
172
+
173
+ $difficulty = filter_input(INPUT_POST, 'difficulty');
174
+
175
+ $budget = filter_input(INPUT_POST, 'budget');
176
+
177
+ try{
178
+
179
+ if (empty($_POST["id"]) )throw new Exception('id不正');
180
+
181
+ $id = (int) $_POST['id'];
182
+
183
+ $dph = new PDO('mysql:host=localhost;dbname=db1;charset=utf8', $user, $pass);
184
+
185
+ $dph->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
186
+
187
+ $dph->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
188
+
189
+ //whereは、どこを更新する??という意味!!
190
+
191
+ $sql = "UPDATE recipes SET recipe_name = ?, category = ?, difficulty = ?, budget = ?, howto = ?, WHERE id = ?";
192
+
193
+ $stmt = $dph->prepare($sql);
194
+
195
+ $stmt->bindValue(1, $recipe_name, PDO::PARAM_STR);
196
+
197
+ $stmt->bindValue(2, $category, PDO::PARAM_INT);
198
+
199
+ $stmt->bindValue(3, $difficulty, PDO::PARAM_INT);
200
+
201
+ $stmt->bindValue(4, $budget, PDO::PARAM_INT);
202
+
203
+ $stmt->bindValue(5, $howto, PDO::PARAM_STR);
204
+
205
+ $stmt->bindValue(6, $id, PDO::PARAM_INT);
206
+
207
+ $stmt->execute();
208
+
209
+ $dph= null;
210
+
211
+ echo "ID:" . htmlspecialchars($id, ENT_QUOTES, 'UTF-8') . "レシピの更新が完了しました。";
212
+
213
+ } catch (Exception $e) {
214
+
215
+ echo "エラー発生: " . htmlspecialchars($e->getmessage(), ENT_QUOTES, 'UTF-8') . "<br>";
216
+
217
+ die();
218
+
219
+ }
220
+
221
+ ?>
222
+
223
+
224
+
225
+ ```
226
+
227
+
228
+
155
229
  ### 試したこと
156
230
 
157
231
 

2

ユーザー名変更

2020/10/26 13:14

投稿

ayaaya_ininin
ayaaya_ininin

スコア0

test CHANGED
File without changes
test CHANGED
@@ -26,9 +26,9 @@
26
26
 
27
27
  <?php
28
28
 
29
- $user = "******";
29
+ $user = "〇〇";
30
30
 
31
- $pass = "******";
31
+ $pass = "〇〇";
32
32
 
33
33
  try {
34
34
 

1

markdownに変更。

2020/10/26 01:04

投稿

ayaaya_ininin
ayaaya_ininin

スコア0

test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
 
22
22
 
23
- PHP.SQL
23
+ ```PHP
24
24
 
25
25
 
26
26
 
@@ -63,6 +63,14 @@
63
63
  }
64
64
 
65
65
  ?>
66
+
67
+ ```
68
+
69
+
70
+
71
+ ```HTML
72
+
73
+
66
74
 
67
75
  <!DOCTYPE html>
68
76
 
@@ -140,7 +148,7 @@
140
148
 
141
149
  </html>
142
150
 
143
-
151
+ ```
144
152
 
145
153
 
146
154