我想用复选框更新数据库。我已经从数据库创建了表。-如果选中“elfogadva”,则值=1。-else 如果未选中“elfogadva”,则(值=0)我有该行的复选框。
<form method="post" action="rendeles.php" id="rendelesek">
<?php
$result=mysql_query("SELECT * FROM megrendeles");
echo "<table border=1>
<tr><th>Szám</th>
<th width=30>Név</th>
<th width=30>Cím</th>
<th width=30>Mobil</th>
<th width=30>E-mail</th>
<th width=70>Rendezvény típusa</th>
<th width=50>Létszám</th>
<th width=150>Helyszín</th>
<th width=50>Átadás</th>
<th width=50>Bontás</th>
<th width=40>Sátor méret</th>
<th width=50>Padlózat</th>
<th width=50>Színpad</th>
<th width=70>Berendezés</th>
<th width=33>Asztal db</th>
<th width=33>Ülés</th>
<th width=33>Ülés db</th>
<th width=33>Füves</th>
<th width=41>Burkolt</th>
<th width=30>Egyéb</th>
<th width=30>Elfogadva</th>
<th width=33>Értékelés</th>
</tr>";
while($row = mysql_fetch_assoc($result)){
echo "<input type='hidden' name='id' value=".$row['id'].">
<tr>
<td>" .$row['id']."</td>
<td>" . $row['nev'] . "</td>
<td>" . $row['cim'] . "</td>
<td>" . $row['mobil'] . "</td>
<td>" . $row['email'] . "</td>
<td>" . $row['rendezveny'] . "</td>
<td>" . $row['letszam'] . "</td>
<td>" . $row['helyszin'] . "</td>
<td>" . $row['atadas'] . "</td>
<td>" . $row['bontas'] . "</td>
<td>" . $row['satormeret'] . "</td>
<td>" . $row['padlozat'] . "</td>
<td>" . $row['szinpad'] . "</td>
<td>" . $row['berendezes'] . "</td>
<td>" . $row['asztal'] . "</td>
<td>" . $row['berendezes_u'] . "</td>
<td>" . $row['ules'] . "</td>
<td>" . $row['fuves'] . "</td>
<td>" . $row['burkolt'] . "</td>
<td>" . $row['egyeb'] . "</td>";
if($row['elfogadva']==1){ //1es ha elfogadva, ha nincs akkor checkbox
echo"<td width=60>" . $row['elfogadva'] . "</td> ";
}else{
echo"<td width=60>
<input type='checkbox' name='elfogadva' value='1'>
</td>";
}
echo"<td>" . $row['ertekeles'] . "</td>
</tr>";
}
echo "</table><br>
<p align='right'><input type='submit' name='submit' class='btn' value='Submit'></p>";
?>
</form>
这是“rendeles.php”:
<?php
$sql = mysql_connect("localhost", "root", "");
mysql_select_db("szakdolgozat") or die( "Unable to select database");
$submit=$_POST['submit'];
$elfogadva=$_POST['elfogadva'];
$id=$_POST['id'];
//if(isset($_POST['elfogadva'])){ $elfogadva = $_POST['elfogadva']; }
echo $elfogadva;
echo"<br>";
echo $id;
if(!isset($_SESSION)){
session_start();
}
$query_rendeles=mysql_query("UPDATE megrendeles SET elfogadva='$elfogadva' WHERE id='$id'");
require_once("lekerdezes_megrendeles.php");
?>
问题:总是发布最后一个“id”。