Bonjours à tous,
Voici mon soucis :
Dans un tableau html je recupere les données d'une table SQL.
A partir de ce tableau je recopie les lignes choisies par checkbox vers une autre table SQL.
Le soucis c'est que cela me recopie que l'ID et non le reste.
Voici mes codes:
Choix.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <?php $db = mysql_connect('localhost', 'root', '') or die('HOST ?'); mysql_select_db('Adherents',$db) or die('DB ?'); $id=$_POST['choix']; if(isset($_POST['choix'])) { foreach($_POST['choix'] as $val) { //affichage des elements du tableau $sql = "INSERT INTO sortie (Nom, Prenom, id ) VALUES ('$Nom','$Prenom', '$val')"; mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error()); echo 'Vos infos on été ajoutées.'; } } header ('location: tri.php'); ?>
Et tableau.php
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TRI</title> </head> <body background="Images/WB02134_.GIF"> <form method='POST' action='choix.php'> <table align="center" border="1"> <?php $db = mysql_connect('localhost', 'root', '') or die('HOST ?'); mysql_select_db('Adherents',$db) or die('DB ?'); $query='Select * from enfants ' ; $result = mysql_query( $query )or exit ('Erreur SQL !'.$query.'<br>'.mysql_error()); echo '<tr> <td>id</td> <td>Nom</td> <td>Prenom</td> <td>Choix</choix></tr'; while($data = mysql_fetch_array($result)) { echo ' <tr><td>'.$data['id'].'</td> <td>'.$data['Nom'].'</td> <td>'.$data['Prenom'].'</td> <td><input type="checkbox" name="choix[]" values='.$data['id'].'/></td></tr>'; } ?> </table> <div align="center"><input type="submit" name="submit" value="Validez" /></div> </form> </body> </html>
Si vous avez une réponse, je vous en remercie par avance
Alain
Partager