フォームにSELECT文で、置いた値をUPDATEしてデータベースの値を更新することができません。
値を設定した状態ならSQL文が動き更新されます。
<?php /******************************************************************************* ■データベース接続 *******************************************************************************/ ```ここに言語を入力 $user = 'AAA'; $pass = 'BBB'; $dns = 'mysql:dbname=AAA;host=mysql333.phy.lolipop.lan;charset=utf8'; //データベースへ接続 $pdo = new PDO($dns, $user, $pass); ``` /******************************************************************************* ■更新処理 *******************************************************************************/ ```ここに言語を入力 if(isset($_POST['update02'])){ try{ $sql = "UPDATE `timecard_regist_form` SET `timecart_no` = ?, `timecart_name` = ?,`timecart_month` = ?,`timecart_day` = ?,`timecart_start_hour` = ?,`timecart_start_min` = ?,`timecart_end_hour` = ?,`timecart_end_min` = ? WHERE `timecart_no` = ?"; $stmt = $pdo->prepare($sql); $array = array($_POST['timecart_no'], $_POST['timecart_name'], $_POST['timecart_month'], $_POST['timecart_day'], $_POST['timecart_start_hour'], $_POST['timecart_start_min'], $_POST['timecart_end_hour'], $_POST['timecart_end_min']); $stmt->execute($array); }catch(Exception $e){ $res = $e->getMessage(); } } <?php if(isset($_POST['update01'])) { ?> <form action="" method="post"> <table class="table" border="1"> <tr> <th>No</th><th>名前</th><th>月</th><th>日</th><th>開始(時)</th><th>開始(分)</th><th>終了(時)</th><th>終了(分)</th><th>編集</th><br> </tr> <tr> <td><?php echo $timecart_no; ?><input type="hidden" name="timecart_no" size="3" value="<?php echo $timecart_no; ?>" required></td> <td><input type="text" name="timecart_name" size="10" value="<?php echo $timecart_name; ?>" required></td> <td><input type="text" name="timecart_month" size="3" value="<?php echo $timecart_month; ?>" required></td> <td><input type="text" name="timecart_day" size="3" value="<?php echo $timecart_day; ?>" required></td> <td><input type="text" name="timecart_start_hour" size="3" value="<?php echo $timecart_start_hour; ?>" required></td> <td><input type="text" name="timecart_start_min" size="3" value="<?php echo $timecart_start_min; ?>" required></td> <td><input type="text" name="timecart_end_hour" size="3" value="<?php echo $timecart_end_hour; ?>" required></td> <td><input type="text" name="timecart_end_min" size="3" value="<?php echo $timecart_end_min; ?>" required></td> <td><input type="submit" name="update02" size="" value="更新"></td> </tr> </table> </form> <?php}
?>
__________________________________________________________________________________________ ```ここに言語を入力 $sql = "UPDATE `timecard_regist_form` SET `timecart_no` = ?, `timecart_name` = ?,`timecart_month` = ?,`timecart_day` = ?,`timecart_start_hour` = ?,`timecart_start_min` = ?,`timecart_end_hour` = ?,`timecart_end_min` = ? WHERE `timecart_no` = ?";
上記のSQL文を、値を設定した下記のSQL文にしたら、更新、UPDATEはできます
$sql = "UPDATE `timecard_regist_form` SET `timecart_name` = 'php02', `timecart_month` = '2', `timecart_day` = '22', `timecart_start_hour` = '10', `timecart_start_min` = '00', `timecart_end_hour` = '22', `timecart_end_min` = '00' WHERE `timecart_no` =1";
回答1件
あなたの回答
tips
プレビュー