Update en utilisant les checkboxs

bonjour,
C'est sûrement une question de noob, mais j'assume. Je suis là pour apprendre. Et puis je suis un peu pressé par le temps, vu qu'il faut que cela fonctionne pour demain matin et je patauge là dedans depuis trop longtemps...

j'ai besoin de faire une mise à jour en cochant un ou plusieurs checkboxs .Le problème c'est qu'il n'y a pas d'identification des checkboxs.

voici mon code au dessous.
Quelqu'un pour m'aider?

<html>
<body>
<form method="post">
<p><b> La table des inscrits </b></p>

<table width="380" border="3">
<tr>
<td width="117"><div align="center"><b>ID</b></div></td>
<td width="117"><div align="center"><b>Nom</b></div></td>
<td width="117"><div align="center"><b>Prénom</b></div></td>
<td width="117"><div align="center"><b>Paiement</b></div></td>
</tr>

<?
include "connexion.php";
$reponse=mysql_query("select * from inscrit where Paiement=0");

while ($row= mysql_fetch_array($reponse))
{
?>
<tr>
<td> <div align="center"><? echo ($row ['id']) ; ?> </div></td>
<td> <div align="center"><? echo ($row ['Nom']) ; ?> </div></td>
<td> <div align="center"><? echo ($row ['Prénom']) ; ?> </div></td>
<td> <div align="center"><input type="checkbox" name="choix[]" value="<? $row ['id'] ?>" ></div></td>
</tr>
<?
}
mysql_close();
?>
<table width="380" border="0">
<tr>
<td></td>
<td><input type='hidden' name='second' value='TRUE'/>
<input type='hidden' name='secondbis' value='FALSE'/>
</td>
<td width="50"><input type="submit" name="enreg" value="Enregistrer" ></td>
<td width="50"><input type="submit" name="vretour" value="Sortir" ></td>
</tr>
</table>
</form>

<?
if(isset($_POST['choix']) && isset($_POST['enreg']) && is_array($_POST['choix']))
{
include ("connexion.php");
$liste=implode(',',$_POST['choix']);

$sql="update inscrit set Paiement=10000 where id IN(".$liste.")";
$req= mysql_query($sql);
mysql_close();

header('location:majBD.php');
}

if (isset($_POST['vretour']))
{header('location:menu_tresorier.php');}

?>

</body>
</html>
Configuration: Windows XP
Internet Explorer 6.0

1 réponse

  1. Bonjour,

    Rapidement :

    1) Il me semble que ta balise form n'est pas correcte. Je te propose :
    <form method="post" action="tonformulaire.php" > ou tonformulaire.php est le nom de ton fichier source. Tu peux aussi utiliser la variable php $_SERVER["PHP_SELF"].

    2) Il faut que ton code de mise à jour soit avant le code d'affichage (sinon la mise à jour s'effectue après avoir réaffiché les données).

    3) Si tu nous disait exactement ce qui ne va pas, ce serait plus facile.

    Codialement.
    0