ユーザーがクラスとアクティビティを複数のフィールドに入力できるフォームがあります。これらのフィールドは次のように宣言されています。
label for ="classact">Classes and Activities</label>
<input type = "text" name = "classact[0]" value ="" id ="classact[0]">
<input type = "text" name = "classact[1]" value ="" id ="classact[1]">
<input type = "text" name = "classact[2]" value ="" id ="classact[2]">
フォームが渡されると、これは挿入で処理するコードです。
$maininsert = "INSERT INTO `camptest`
(`name`, `city`, `phone`, `photo`)
VALUES
('$_POST[name]', '$_POST[city]', '$_POST[phone]', '$photoinfo')
SET @lid = LAST_INSERT_ID()
";
$classactinsert = "INSERT INTO `class_act`
(`cid`";
for($i = 0; $i < 3; $i++)
{
if(isset($_POST['classact'][$i]))
{
$temp = $i+1;
$classactinsert = $classactinsert . ",`act$temp`";
}
}
$classactinsert = $classactinsert . ")
VALUES
('@lid'";
for($i = 0; $i < 3; $i++)
{
if(isset($_POST['classact'][$i]))
{
$classactinsert = $classactinsert . ",'$_POST[classact][$i]";
}
}
$classactinsert = $classactinsert . ")";
$indata = $maininsert . $classactinsert;
$result = mysql_query($indata);
私はそれがたくさんのコードであることを理解していますが、フォームに記入して送信すると、これが生成されるクエリです:
INSERT INTO `camptest` (`name`, `city`, `phone`, `photo`) VALUES ('Multiple Activities', 'Nowhere', '555-555-1111', 'images/51127f6b06d1e.jpg') SET @lid = LAST_INSERT_ID() INSERT INTO `class_act` (`cid`,`act1`,`act2`,`act3`) VALUES ('@lid','Array[0],'Array[1],'Array[2])
クエリは挿入されていませんが、エラーをオンにしても、エラーは返されません。
私の主な質問は、act1、act2、およびact3の値がArray [0]、Array [1]、およびArray [2]として表示される原因となっている、何が間違っているのかということです。
私の二次的な質問は、これについても正しい方法で行っているのかということです。私はphpに少し慣れていないので、これを難しい方法でやっているのではないかと心配しています。
ご不明な点がございましたら、お気軽にお問い合わせください。