さまざまなテキストフィールドとチェックボックスフィールドを含むHTMLフォームがあります。テキストフィールドを正しいテーブルに投稿していますが、チェックボックスの応答がまったく投稿されていません(別のテーブルに投稿することを目的としています)。
これが私のHTMLフォームです:
<!Doctype html>
<html>
<?php include 'C:\xampp\htdocs\paxdb\head.php';
include 'config/menu.php';?>
<div id="dataentry">
<!--This section is the demographic text field area-->
<form method="post" action="dataentered.php">
First Name: <input type="text" id="First_Name" name="First_Name"/></br>
</br>
Last Name: <input type="text" id="Last_Name" name="Last_Name"/></br>
</br>
E-mail: <input type="text" id="email" name="email"/></br>
</br>
<!--This section is the age range checkbox selection area-->
<p><u><b>Age Range</b></u></p>
<input type="checkbox" name="age[]" id="20-25" value="1"/> 20-25</br>
<input type="checkbox" name="age[]" id="26-30" value="1"/> 26-30</br>
<input type="checkbox" name="age[]" id="31-35" value="1"/> 31-35</br>
<input type="checkbox" name="age[]" id="36-40" value="1"/> 36-40</br>
<input type="checkbox" name="age[]" id="41-45" value="1"/> 41-45</br>
</div>
<p><u><b>What City or region would you like to visit in the US or Canada?:</b></u></p>
<textarea name="comment2" rows="4" cols="50"></textarea>
<?php include 'footer.php';?>
</div>
</body>
</html>
これが私が試しているPHPコードですが、テキストフィールドのみが機能しています。
<html>
<?php
$host="localhost";
$username="someusername";
$password="somepassword";
$dbname="somedbname";
$dbc = mysql_connect($host, $username, $password, $dbname);
if (!$dbc)
{
die('Error connecting to MySQL server' . mysql_error());
}
mysql_select_db($dbname, $dbc);
//send pax data to pax database table
$first_name=$_POST['First_Name'];
$last_name=$_POST['Last_Name'];
$email=$_POST['email'];
mysql_query("INSERT INTO pax (First_Name, Last_Name, email)
VALUES('$first_name','$last_name','$email')");
//send age checkbox data to age database table
$age = $_POST['age'];
foreach($age as $range) mysql_query("INSERT INTO age ($age) VALUES ('$range')") or die (mysql_error());
mysql_close($dbc);
どんな助けでも大歓迎です。
編集明確にするために: mysqlテーブル'age'には次のフィールドがあります:age_id(キー)、pax_id(フォームの先頭にあるテキストフィールドデータのインデックス)、20-2526-30など。