###前提・実現したいこと
ここに質問したいことを詳細に書いてください
phpの練習でDB登録式の計算機を作っています。
チェックボックスの付いている項目だけ計算し、更新できるようにしたいです。
###発生している問題・エラーメッセージ
更新しても、テキストボックスに入れた数値が反映されず、DBの最初に登録した数値で表示されます。
エラーは発生しておらず、動作はしております。
php
1//更新・削除処理 2if( isset( $_POST["selchk"])) { 3 $chk = $_POST["selchk"]; 4 $max =count($chk); 5 //print_r($chk); 6 //更新 7 if(isset($_POST["koushin"]) && $_POST["db_first"] && $_POST["db_second"] && $_POST["db_method"]){ 8 $result = mysql_query('SELECT * FROM calculation'); 9 for($i = 0; $i < $max; $i++){ 10 list($key, $first_fix) = each($_POST["db_first"]); 11 list($key2,$second_fix) = each($_POST["db_second"]); 12 list($key3,$method_fix) = each($_POST["db_method"]); 13 14 $db_calnumber = keisan($method_fix,$first_fix,$second_fix); 15 $answer_fix = gusukisu($db_calnumber,$first_fix, $second_fix); 16 $odd_even_fix = odd_even($db_calnumber); 17 18 $updated = date( "Y/m/d H:i:s", time()); 19 20 //更新処理 21 $sql = "UPDATE calculation 22 SET updated='".$updated."',first='".$first_fix."',second='".$second_fix."',answer='";.$answer_fix."',method='".$method_fix."',odd_even='".$odd_even_fix."' 23 WHERE id='".$chk[$i]."'"; 24 $result_flag = mysql_query($sql); 25 $result = mysql_query('SELECT * FROM calculation'); 26 } 27 } 28 $result_flag = mysql_query($sql); 29 if ($result_flag) { 30 echo "更新しました"; 31 }else{ 32 print(mysql_error()); 33 //echo "更新に失敗しました<br />"; 34 }
html
1<table> 2 <tr> 3 <th><input type="checkbox" name="all" onClick="AllChecked(this);" /></th> 4 <th>#</th> 5 <th>式</th> 6 <th>答え</th> 7 <th>奇/偶</th> 8 <th>登録日</th> 9 <th>更新日</th> 10 </tr> 11 <tr> 12<?php 13 14//データベースのレコードカウントした結果の数 15$recordcount = mysql_num_rows($result); 16 17//取得したデータを順に表示 18for($i=1; $i<= $recordcount; $i++) { 19 //DBの値から文字列に置換 20 $row = mysql_fetch_array($result); 21 echo "<tr>"; 22 echo "<td><input type=checkbox name=selchk[] value=".$row["id"]."></td>"; 23 echo "<td>".$i."</td>"; 24 echo "<td><input type=input name=db_first[] value=".$row["first"]."><input size=1 type=input name=db_method[] value=".$row["method"]."><input type=input name=db_second[] value=".$row["second"]."></td>"; 25 echo "<td>".$row["answer"]."</td>"; 26 echo $row["odd_even"]; 27 echo "<td>".$row["created"]."</td>"; 28 echo "<td>".$row["updated"]."</td>"; 29 echo "</tr>\n"; 30} 31 32?> 33</tr> 34</table>
回答1件
あなたの回答
tips
プレビュー