<?php
print "<pre>";
print_r($_POST);
print "</pre>";
//formから受け取り
//Array
//(
// [checkall] => on
// [uid] => Array
// (
// [0] => 21
// [1] => 20
// [2] => 19
// )
//
// [ucheck] => Array
// (
// [0] => OK
// [1] => OK
// [2] => OK
// )
//
// [update] => 更新
//)
try {
$db = new PDO('mysql:host=localhost;dbname=project;charset=utf8', 'phpusr', 'phppass');
if (isset($_POST['update'])) {
$stt = $db->prepare('UPDATE project SET ucheck=:ucheck WHERE uid=:uid');
$stt->bindValue(':ucheck', $_POST['ucheck']);
$stt->bindValue(':uid', $_POST['uid']);
$stt->execute();
}
} catch(PDOException $e) {
die('エラーメッセージ:'.$e->getMessage());
}
//DBのログ
//Query UPDATE project SET ucheck='Array' WHERE uid='Array'
PHP初心者でmysqlの複数レコードの更新の方法が分からないので
お手数ですが教えてください。
formから[uid]と[ucheck]を受け取りupdate処理をしたいのですが
繰り返し構文を作ろうとしてもうまくいかない為お願いします。
テーブルの定義がわからないと答えようがありません。定義を提示してください。
回答3件
あなたの回答
tips
プレビュー