今後のイベントに使用したい出席リストを作成しています。
人がウェブサイトにログオンするとき、彼/彼女と他の人がイベントに出席するかどうかを選択することができます。
if ($res && mysql_num_rows($res) >= 1)
{
echo '<form method="post" action="guest.php">';
echo '<table border="10">
<tr>
<td>Name</td>
<td>Present</td>
</tr>';
while ($row = mysql_fetch_array($res))
{
echo '<tr>
<td>'.$row['guestId']." ".$row['firstName'].'</td>
<td><input type=\'checkbox\' name=\'present[]\' value='.$row['guestId'].'></td>
</tr>';
}
echo '</table>';
echo '<input type="submit" name="submit" value="submit">';
} else {
echo 'No data found!';
}
ここではguestId
、データベースへの書き込みに使用する値にを書き込んでいます。
if( isset($_POST['present']) ) {
foreach($_POST['present'] as $value){
$query=mysql_query("INSERT INTO present (gastId, present) VALUES (".$value.", 1)");
$resultadd=mysql_query($query) or die("Errore insert G: ".mysql_error());
}
}
これを行うためのより良い方法はありますか?これが正しい方法だとは想像できないからです。