2011-12-23 3 views
1

チェックボックスを使用してSQLテーブルのデータを変更したいとします。私は正常に私のテーブルのすべてのデータをエコーし​​ました。しかし、私は削除することはできません。新しいデータを入力した後、チェックボックスをクリックして送信します。データは元のデータに戻ります。誰でも私を助けてくれる?どうもありがとうございます。チェックボックスを使用してデータを変更する

<?php 


include_once("mesparametres.inc.php"); 
$sql="SELECT * FROM poisson"; 
$result=mysql_query($sql); 

// Count table rows 
$count=mysql_num_rows($result); 
?> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 
<form name="form1" method="post" action="modifier.php"> 
<tr> 
<td> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 


<tr> 
<td align="center"><strong>Id</strong></td> 
<td align="center"><strong>Nom</strong></td> 
<td align="center"><strong>Classe</strong></td> 
<td align="center"><strong>eau</strong></td> 
<td align="center"><strong>nourriture</strong></td> 
<td align="center"><strong>couleur</strong></td> 
<td align="center"><strong>taille</strong></td> 
<td align="center"><strong>vie</strong></td> 
<td align="center"><strong>dateacqui</strong></td> 
<td align="center"><strong>modifier</strong></td> 

</tr> 
<?php 
while($rows=mysql_fetch_array($result)) 
{ 
?> 

<tr> 
<td align="center"><input type="hidden" name="id<? echo $rows['id']; ?>" value="<? echo $rows['id']; ?>" /><? echo $rows['id']; ?></td> 
<td align="center"><input name="nom<? echo $rows['id']; ?>" type="text" id="nom" value="<? echo $rows['nom']; ?>"></td> 
<td align="center"><input name="classe<? echo $rows['id']; ?>" type="text" id="classe" value="<? echo $rows['classe']; ?>"></td> 
<td align="center"><input name="eau<? echo $rows['id']; ?>" type="text" id="eau" value="<? echo $rows['eau']; ?>"></td> 
<td align="center"><input name="nourriture<? echo $rows['id']; ?>" type="text" id="nourriture" value="<? echo $rows['nourriture']; ?>"></td> 
<td align="center"><input name="couleur<? echo $rows['id']; ?>" type="text" id="couleur" value="<? echo $rows['couleur']; ?>"></td> 
<td align="center"><input name="taille<? echo $rows['id']; ?>" type="text" id="taille" value="<? echo $rows['taille']; ?>"></td> 
<td align="center"><input name="vie<? echo $rows['id']; ?>" type="text" id="vie" value="<? echo $rows['vie']; ?>"></td> 
<td align="center"><input name="dateacqui<? echo $rows['id']; ?>" type="text" id="dateacqui" value="<? echo $rows['dateacqui']; ?>"></td> 
<td align="center"><input name="modifier[]>" type="checkbox" id="modifier[]" value="<? echo $rows['id']; ?>" ></td> 
</tr> 
<?php if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];}?> 
<?php 
} 
?> 
<tr> 
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> 
</tr> 
</table> 
</td> 
</tr> 
</form> 
</table> 
<?php 
// Check if button name "Submit" is active, do this 
if($Submit) 
{ 
foreach($_POST['id'] as $id) 
{ 


$sql1="UPDATE poisson SET nom='".$_POST["nom".$id]."', classe='".$_POST["classe".$id]."', eau='".$_POST["eau".$id]."',nourriture='".$_POST["nourriture".$id]."',couleur='".$_POST["couleur".$id]."',taille='".$_POST["taille".$id]."',vie='".$_POST["vie".$id]."',dateacqui='".$_POST["dateacqui".$id]."' WHERE id='".$id."'"; 
$result1=mysql_query($sql1); 
} 
} 


mysql_close(); 
?> 
</body> 
</html> 

答えて

0

まず私は :)明確にするための変数でPOSTデータはその後、それを保存せずにクエリを実行しようとすることを保存するためにお勧めしたいすなわち:

mysql_query("UPDATE table SET nom='variable1', classe='variable2' WHERE id='condition'; 

というように、あなたのようなした。また、 '確認' 属性を必要とする、すなわちchecked="yes"

0

チェックボックスはcheckedHTML attributeに基づいて確認されたりしていない、いないvalue属性:

この:

<input type="checkbox" checked="checked" /> 

ないこの:

<input type="checkbox" value="1" /> 

値は、たとえばabをグループ化したときにフォームと共に送信されます同じname属性を使用して、チェックボックスを解除します。

関連する問題