2 pièce(s) jointe(s)
garder un chekbox checked
Bonsoir à tous,
J'ai 2 formulaires de types checkbox, "preparation" et "livraison", qui se trouvent eux-mêmes dans des tableaux générés dynamiquement.
Je voudrais garder les checkbox qui se trouvent dans ces formulaires
checkées quand on recharge la page, après avoir cliqué sur le bouton 'ok'.
D'abord, je dois écrire la valeur 1 dans les champs preparation_commande et livraison_commande(boolean) qui se trouvent dans ma table commandes_clients, mais je n'y arrive même pas...ensuite je devrais pouvoir récupérer cette valeur 1
et mettre le chekbox en checked.
Je n'ai pas d'erreur mais toutes mes cases sont décochées au réaffichage de la page, et j'écris rien dans ma BD. Si qqn voit comment faire pour arriver au résultat souhaité, il est le bienvenu. Merci.
J'ai mis une image du formulaire en attachement, ainsi qu'une image de la table commandes_clients...
Et voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
<form style="text-align:center;" method="post" action="admin.php">
<table align="center" width="250">
<tr>
<td colspan="2" style="text-align:center"><input class="submit" name="commandes" type="submit" value="Commandes" /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['commandes']))
{
if($connection = ConnectBD())
{
$sql ='SELECT prenom_user, nom_user, adresse_user, cp_user, tel_user, ref_produit, quantite_produit_commande, ref_commande_client
FROM produits_commandes
INNER JOIN commandes_clients ON produits_commandes.ref_commande_client=commandes_clients.id_commande_client
INNER JOIN users ON commandes_clients.ref_user=users.email_user
WHERE date_commande=CURRENT_DATE()';
if($requete = TraiterRequete($sql))
{
echo '<table class="propricom">
<tbody>
<tr>
<th class="propricomtitles">Prénom</th>
<th class="propricomtitles">Nom</th>
<th class="propricomtitles">Adresse</th>
<th class="propricomtitles">CP</th>
<th class="propricomtitles">Téléphone</th>
<th class="propricomtitles">Code produit</th>
<th class="propricomtitles">Quantité</th>
<th class="propricomtitles">N°commande</th>
<th class="propricomtitles">Préparation</th>
<th class="propricomtitles">Livraison</th>
</tr>';
$b=0;
while($data = mysql_fetch_array($requete))
{
$a=$data['ref_commande_client'];
if($b!=$a)
{
echo '<tr>';
echo '<td class="produits2">'.$data['prenom_user'].'</td><td class="produits2">'.$data['nom_user'].'</td><td class="produits2">'.$data['adresse_user'].'</td><td class="produits2">'.$data['cp_user'].'</td><td class="produits2">'.$data['tel_user'].'</td><td class="produits2">'.$data['ref_produit'].'</td><td class="produits2">'.$data['quantite_produit_commande'].'</td><td class="produits2">'.$data['ref_commande_client'].'</td>
<td class="produits2">
<form method="post" action="admin.php">
<input type="submit" name="ok1" value="ok" />
<input type="checkbox" name="preparation" value="" ';
if(isset($_POST['ok1']) && !empty($_POST['preparation']))
{
echo 'checked="checked"';
$sql2='UPDATE commandes_clients SET preparation_commande=1 WHERE id_commande_client="'.$data['ref_commande_client'].'"';
$requete2 = TraiterRequete($sql2);
}
echo' />
</form>
</td>
<td class="produits2">
<form method="post" action="admin.php">
<input type="submit" name="ok2" value="ok" />
<input type="checkbox" name="livraison" value="" ';
if(isset($_POST['ok2']) && !empty($_POST['livraison']))
{
echo 'checked="checked"';
$sql3='UPDATE commandes_clients SET livraison_commande=1 WHERE id_commande_client="'.$data['ref_commande_client'].'"';
$requete3 = TraiterRequete($sql3);
}
echo' />
</form>
</td>';
echo '</tr>';
}
else
{
echo '<tr>';
echo '<td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits"></td><td class="produits">'.$data['ref_produit'].'</td><td class="produits">'.$data['quantite_produit_commande'].'</td><td class="produits"></td><td class="produits"></td><td class="produits"></td>';
echo '</tr>';
}
$b=$data['ref_commande_client'];
}
echo'</tbody>
</table>';
}
}mysql_close($connection);
}
?> |