Précédent   Forum des professionnels en informatique > PHP > Langage > Formulaires
Formulaires Forum d'entraide sur les formulaires avec PHP. Avant de poster -> FAQ formulaires, Cours de formulaires et Sources de formulaires
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 08/07/2008, 01h09   #1
Futur Membre du Club
 
Inscription : avril 2008
Messages : 79
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 79
Points : 15
Points : 15
Par défaut effacer par checkbox dans un formulaire

slt je voudrais effacer des membre de ma base de données en cochant un ou plusieurs membres puis en cliquant sur submir,y a t'il des idees merciiiiiiiii
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
 
<html>
<head>
<style type="text/css">
<!--
.Style1 {color: #000000}
-->
</style>
</head>
<body link="#00CCFF" vlink="#00CCFF" text="#FFFFF" bgcolor="#000000" alink="#00CCFF">
<?php
include_once("db_connect.php"); 
 
 $requete="select pseudo,email,prenom from gx_user where statut not like 'admin'";
 $rep=mysql_query($requete);
 
 if($rep==0)
 
 print("table membre vide<br>");
 
else
 {
echo "<form name=form method=post>";
echo "<center><h1><blink>La liste des membres</blink></h1></center>";
echo "<table border=2>";
echo "<tr><th>pseudo</th><th>mail</th><th>prenom</th><th>Effacer</th></tr>";
 
$id=0; 
while($ligne=mysql_fetch_row($rep))
{ 
$id++; 
$var0=$ligne[0];
$var1=$ligne[1];
$var2=$ligne[2];
 
 
 
echo "<tr><th>$var0</th><th>$var1</th><th>$var2</th><th><input type=\"checkbox\" name=".$id." ></th></tr>";
}
 echo "</table>";
 
 
 
  echo "<input type=submit name=suppression value=effacer>";
 echo "</form>";
 }
?>
<p align="center"><a href="admin.php"><img src="gifs/retour.gif" width="107" height="43"></a></p>
</body>
</html>
timboy11 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 09h53   #2
Membre Expert
 
Inscription : octobre 2002
Messages : 1 141
Détails du profil
Informations personnelles :
Âge : 32
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : octobre 2002
Messages : 1 141
Points : 1 204
Points : 1 204
Envoyer un message via MSN à Raideman
Pour ta checkbox, fais plutot:

Code :
<input type=\"checkbox\" name="id[]" value=".$id." >
Puis dans le traitement du formulaire:

Code :
1
2
3
4
5
6
7
if(!empty($_POST['id']))
{
   foreach($_POST['id'] as $id){
       $requete="delete from XXXX where membre_id='".$id."'";
       $exe=mysql_query($requete);
  }
}
Raideman est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 10h30   #3
Futur Membre du Club
 
Inscription : avril 2008
Messages : 79
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 79
Points : 15
Points : 15
slt merci pour ton aide j'ai corrigé,il m'affiche le tableau,mais si je coche les membres et si je clique sur mon bouton,rien ne se passe pas de suppression.voila lo 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
 
<?php
include_once("./db_connect.php"); 
 
if(!empty($_POST['id'])
{
   foreach($_POST['id'] as $id){
       $requete="delete from gx_user where id='".$id."'";
       $exe=mysql_query($requete);
  }
}
 
 $requete="select id,pseudo,email,prenom from gx_user where statut not like 'admin'";
 $rep=mysql_query($requete);
 
 if($rep==0)
 
 print("table membre vide<br>");
 
else
 {
echo "<form name=form method=post>";
echo "<center><h1><blink>La liste des membres</blink></h1></center>";
echo "<table border=2>";
echo "<tr><th>identifiant</th><th>pseudo</th><th>email</th><th>PRENOM</th><th>Effacer</th></tr>";
 
 
while($ligne=mysql_fetch_row($rep))
{ 
$var0=$ligne[0];
$var1=$ligne[1];
$var2=$ligne[2];
$var3=$ligne[3];
 
 
echo "<tr><th>$var0</th><th>$var1</th><th>$var2</th><th>$var3</th><th><input type=\"checkbox\" name=\"id[]\" value=\".$id.\" ></th></tr>";
}
 echo "</table>";
 
 
 
  echo "<input type=submit name=suppression value=effacer>";
 echo "</form>";
 }
?>
timboy11 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 11h26   #4
Futur Membre du Club
 
Inscription : avril 2008
Messages : 79
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 79
Points : 15
Points : 15
Par défaut effacer par checkbox

slt je voudrais effectuer des suppression sur ma table mysql en cochant les membres et en cliquant sur un bouton,voila mon code,il m'affiche les members mais et les requetes mais pas de action sur la base.
Fichiers attachés
Type de fichier : rar Nouveau dossier.rar (3,3 Ko, 0 affichages)
timboy11 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 12h33   #5
Membre éprouvé
 
Avatar de defcon_suny
 
Développeur informatique
Inscription : décembre 2006
Messages : 436
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : décembre 2006
Messages : 436
Points : 486
Points : 486
Salut,

La valeur de ton checkbox n'était pas bonne... essaie ceci :

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
 
<?php
include_once("./db_connect.php"); 
if(!empty($_POST['id'])){
   foreach($_POST['id'] as $id){
       $requete="delete from gx_user where id='".$id."'";
       $exe=mysql_query($requete);
  }
}
 
$requete="select id,pseudo,email,prenom from gx_user where statut not like 'admin'";
$rep=mysql_query($requete);
if($rep==0)
	print("table membre vide<br>");
else{
	echo '<form name="form" method="post">';
	echo '<center><h1><blink>La liste des membres</blink></h1></center>';
	echo '<table border="2">';
	echo '<tr><th>identifiant</th><th>pseudo</th><th>email</th><th>PRENOM</th><th>Effacer</th></tr>';
	while($ligne=mysql_fetch_row($rep)){ 
		$var0=$ligne[0];
		$var1=$ligne[1];
		$var2=$ligne[2];
		$var3=$ligne[3];                                                                             
		echo '<tr><td>'.$ligne[0].'</td><td>'.$ligne[1].'</td><td>'.$ligne[2].'</td><td>'.$ligne[3].'</td><td><input type="checkbox" name="id" value="'.$ligne[0].'"></td></tr>';
	}
echo '</table>';
echo '<input type=submit name=suppression value=effacer>';
echo '</form>';
}
?>
++
defcon_suny est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 12h37   #6
Futur Membre du Club
 
Inscription : avril 2008
Messages : 79
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 79
Points : 15
Points : 15
merci
l me donne ce msg

Invalid argument supplied for foreach() in C:\wamp\www\ILEIC\admin\affich membre.php on line 5
timboy11 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 12h42   #7
Membre éprouvé
 
Avatar de defcon_suny
 
Développeur informatique
Inscription : décembre 2006
Messages : 436
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : décembre 2006
Messages : 436
Points : 486
Points : 486
Chez moi ca tourne!

Si tu n'as pas copier coller le code précédent... remets ton code ici.
defcon_suny est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 12h44   #8
Futur Membre du Club
 
Inscription : avril 2008
Messages : 79
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 79
Points : 15
Points : 15
c quant je coche puis je clique sur effacer qu'il me donne cette erreur,mais l'affichage des donnes marche b1.
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
 
<?php
 
 
include_once("./db_connect.php"); 
if(!empty($_POST['id'])){
   foreach($_POST['id'] as $id){
       $requete="delete from gx_user where id='".$id."'";
       $exe=mysql_query($requete);
  }
}
 
$requete="select id,pseudo,email,prenom from gx_user where statut not like 'admin'";
$rep=mysql_query($requete);
if($rep==0)
	print("table membre vide<br>");
else{
	echo '<form name="form" method="post">';
	echo '<center><h1><blink>La liste des membres</blink></h1></center>';
	echo '<table border="2">';
	echo '<tr><th>identifiant</th><th>pseudo</th><th>email</th><th>PRENOM</th><th>Effacer</th></tr>';
	while($ligne=mysql_fetch_row($rep)){ 
		$var0=$ligne[0];
		$var1=$ligne[1];
		$var2=$ligne[2];
		$var3=$ligne[3];                                                                             
		echo '<tr><td>'.$ligne[0].'</td><td>'.$ligne[1].'</td><td>'.$ligne[2].'</td><td>'.$ligne[3].'</td><td><input type="checkbox" name="id" value="'.$ligne[0].'"></td></tr>';
	}
echo '</table>';
echo '<input type=submit name=suppression value=effacer>';
echo '</form>';
}
timboy11 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 12h47   #9
Membre éprouvé
 
Avatar de defcon_suny
 
Développeur informatique
Inscription : décembre 2006
Messages : 436
Détails du profil
Informations personnelles :
Localisation : Belgique

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : décembre 2006
Messages : 436
Points : 486
Points : 486
Autant pour moi!

Dans ton formulaire remplace :
Code :
1
2
 
<input type="checkbox" name="id" value="'.$ligne[0].'">
Par:
Code :
1
2
 
<input type="checkbox" name="id[]" value="'.$ligne[0].'">
ca devrait aller ;-)
defcon_suny est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/07/2008, 12h49   #10
Futur Membre du Club
 
Inscription : avril 2008
Messages : 79
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 79
Points : 15
Points : 15
merci ça marche impec,et dsl pour le derangement
merci encore
timboy11 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h07.


 
 
 
 
Partenaires

Hébergement Web