質問編集履歴
2
試したこと
test
CHANGED
File without changes
|
test
CHANGED
@@ -228,6 +228,71 @@
|
|
228
228
|
?>
|
229
229
|
```
|
230
230
|
|
231
|
+
### 調査したこと、試したこと
|
232
|
+
|
233
|
+
メールアドレスとお問い合わせ内容の表示が正しくなるよう、該当の行を入れ替えたー改善なし
|
234
|
+
<td nowrap class="email"><?= $value['email']."<br>";?></td>
|
235
|
+
<td class="contact"><?= $value['contact']."<br>";?></td>
|
236
|
+
|
237
|
+
```html
|
238
|
+
|
239
|
+
<form method="POST" action="submit.php">
|
240
|
+
<label for="name">氏名:</label>
|
241
|
+
<input type="text" name="name" required><br>
|
242
|
+
|
243
|
+
<label for="ruby">フリガナ:</label>
|
244
|
+
<input type="text" name="ruby" required><br>
|
245
|
+
|
246
|
+
<label for="phone">電話番号:</label>
|
247
|
+
<input type="text" name="phone" required><br>
|
248
|
+
|
249
|
+
<label for="email">メールアドレス:</label>
|
250
|
+
<input type="email" name="email" required><br>
|
251
|
+
|
252
|
+
<label for="contact">お問い合わせ内容:</label>
|
253
|
+
<textarea name="contact" required></textarea><br>
|
254
|
+
|
255
|
+
<input type="submit" value="送信">
|
256
|
+
</form>
|
257
|
+
```
|
258
|
+
|
259
|
+
```submit.php
|
260
|
+
<?php
|
261
|
+
require_once('database.php');
|
262
|
+
|
263
|
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
264
|
+
$name = $_POST['name'];
|
265
|
+
$ruby = $_POST['ruby'];
|
266
|
+
$phone = $_POST['phone'];
|
267
|
+
$email = $_POST['email'];
|
268
|
+
$contact = $_POST['contact'];
|
269
|
+
|
270
|
+
try {
|
271
|
+
$pdo->beginTransaction();
|
272
|
+
|
273
|
+
$sql = "INSERT INTO contacts (name, ruby, phone, email, contact, created_at) VALUES (:name, :ruby, :phone, :email, :contact, NOW())";
|
274
|
+
$stmt = $pdo->prepare($sql);
|
275
|
+
$stmt->bindParam(':name', $name);
|
276
|
+
$stmt->bindParam(':ruby', $ruby);
|
277
|
+
$stmt->bindParam(':phone', $phone);
|
278
|
+
$stmt->bindParam(':email', $email);
|
279
|
+
$stmt->bindParam(':contact', $contact);
|
280
|
+
$stmt->execute();
|
281
|
+
|
282
|
+
$pdo->commit();
|
283
|
+
|
284
|
+
echo "データの登録が完了しました。";
|
285
|
+
} catch (PDOException $error) {
|
286
|
+
$pdo->rollBack();
|
287
|
+
header('Content-Type: text/plain; utf8_general_ci', true, 500);
|
288
|
+
exit($error->getMessage());
|
289
|
+
}
|
290
|
+
}
|
291
|
+
?>
|
292
|
+
|
293
|
+
```
|
294
|
+
|
295
|
+
|
231
296
|
|
232
297
|
### 補足情報(FW/ツールのバージョンなど)
|
233
298
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -216,7 +216,7 @@
|
|
216
216
|
define('DB_HOST', 'localhost');
|
217
217
|
define('DB_NAME', 'cafe');
|
218
218
|
define('DB_USER', 'blog_user');
|
219
|
-
define('DB_PASSWORD', '
|
219
|
+
define('DB_PASSWORD', 'ここはPW入力しています');
|
220
220
|
|
221
221
|
try {
|
222
222
|
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
|