以下のコードですが、チェックした複数の変数"ids[]"と、それにリンクした複数の変数"counts[]"をそれぞれインサートしたいのですが、implodeだとコンマ区切りの1つの変数としかみなされません。
foreach($_POST[counts] as $counts) としても、複数ある変数の内最後のものしかinsertされません。
どなたか解決方法を教えてください。宜しくお願い致します。
CREATE TABLE IF NOT EXISTS `list` ( `id` varchar(10) NOT NULL, `count` varchar(10) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
<form method="post" action="" > <table> <tr><td><input type="checkbox" name="ids[]" value="<?php print htmlspecialchars( $result["id"], ENT_QUOTES) ?>" /></td> <td><?php print htmlspecialchars( $result["name"], ENT_QUOTES) ?></td> <td><<?php print htmlspecialchars( $result["standard"], ENT_QUOTES) ?></td> <td><?php print number_format(htmlspecialchars( $result["price"], ENT_QUOTES)) ?>円</td> <td><input type="number" id="<?php print htmlspecialchars( $result["id"], ENT_QUOTES) ?>" name="counts[]" min="1" max="10" style="text-align:center;" /></td> </tr> </table> <input type="submit" value="買い物かごに入れる"> </form>
<?php $id=$_REQUEST[id]; $count=$_REQUEST[count]; $pdo = new PDO("mysql:host=xxx; dbname=xxx; charset=utf8", "xxx", "xxx", array( PDO::ATTR_EMULATE_PREPARES => false ) ); $sql = <<< SQL insert into list( id,count) values( :id,:count) SQL; $condition = array( ":id" =>implode(", ",$id), ":count" =>implode(", ",$count), ); $statement = $pdo->prepare( $sql ); $result = $statement->execute( $condition ); if( $result ){ } ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/27 00:13
2016/11/27 00:35
2016/11/27 00:56
2016/11/27 01:10