PHPとMYSQLでの表作成
phpとmysqlを使い表を作っていて、inputのsubmitを押すとUPDATEされるという仕様なのですがUPDATEをかけた時に正しくUPDATEされません。
1番目のボタンを押した後、2番目のボタンを押すと1番目のボタンのcreatedが変更されます。時間も少しおかしいです。
php
1<?php 2session_start(); 3require('dbconnect.php'); 4 5$row_count = []; 6$sql = "SELECT * FROM members ORDER BY name"; 7$stmt = $db->query($sql); 8 9?> 10<!DOCTYPE html> 11<html lang="ja"> 12<head> 13 <meta charset="UTF-8"> 14 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 15 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 16 <link rel="stylesheet" href="profile.css"> 17 <title>Document</title> 18</head> 19<body> 20 <form method="post" action=""> 21 <table border="1"> 22 <tr> 23 <th>名前</th> 24 <th>取引終了時間</th> 25 </tr> 26 <?php foreach($stmt as $row): ?> 27 <tr> 28 <td><?php echo($row['name']); ?></td> 29 <td><?php echo($row['created']); ?></td> 30 <td><input type="submit" name="<?php echo($row['name']); ?>" value="時間更新"></td> 31 </tr> 32 <?php 33 if (isset($_POST[$row['name']])) { 34 print($row['name']); 35 $stmt = $db->prepare('UPDATE members SET created = NOW() WHERE name = :name '); 36 $stmt->execute(array(':name' => $row['name'])); 37 } 38 ?> 39 <?php endforeach; ?> 40 </form> 41 <table> 42 </form> 43 <h1><a href="index.php">入力画面</a></h1> 44</body> 45</html>