Bonjour à tous j'ai besoin de votre aide sur un pb en en fait je suis débutant en php en je but à quelques pbs .
bon là je veux faire communiquer deux formulaires (on peut dire) recuperer une varaible garce à POST (GET) et utiliser la variable pour executer une requete dans le second formulaire
stocke.php
stocki.php
Code : 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Stock disponible - Gestion EPI</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #A9EAFE; } --> </style></head> <body> <center> <?php // set up DB try { $strConnection = 'mysql:host=localhost;dbname=gestion_epi'; $arrExtraParam= array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); $pdo = new PDO($strConnection, 'root', '', $arrExtraParam); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage(); die($msg); } $query = 'SELECT * FROM epi WHERE nom = ?'; $mes = $pdo->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); if (isset($_GET['test'])) { $mes->execute(array($_GET['test'])); } $nbligne = $mes->rowCount();//nombre lignes $nbcolonne = $mes->columnCount();//nombre colonnes if($nbligne>0){ //recuperation nom des colonnes $colums = $mes->fetch(PDO::FETCH_ASSOC); $x=1; foreach($colums as $field_name=>$value) { $col[$x] = $field_name; $x++; } //tableau echo '<table cellpadding="2" cellspacing="2" border="5" class="display" id="lignecommande"> <thead> <tr>'; //titre du tableau for($i=1;$i<$x;$i++) echo '<th>'.strtoupper($col[$i]).'</th>'; echo '<th>CHOIX</th>'; echo' </tr> </thead> <tbody>'; //valeur des lignes $alternate=0; $mes->execute(); $y=0; foreach($mes->fetchall() as $t){ $y=$y+1; if($alternate%2==0){ echo ' <tr id="'.$y.'" class="gradeB">'; for($i=1;$i<$x;$i++){ echo '<td class="center">'.$t[$col[$i]].'</td>'; } echo '<td class="center"><input type="checkbox" name="check'.$y.'" value="'.$t[$col[1]].'"></td>'; echo' </tr>'; } else{ echo ' <tr id="'.$y.'" class="gradeD">'; for($i=1;$i<$x;$i++){ echo '<td class="center">'.$t[$col[$i]].'</td>'; } echo '<td class="center"><input type="checkbox" name="check'.$y.'" value="'.$t[$col[1]].'"></td>'; echo' </tr>'; } $alternate=$alternate+1; } echo ' </tbody> <tfoot> <tr>'; /*for($i=1;$i<$x;$i++) echo '<th>'.strtoupper($col[$i]).'</th>'; echo '<th>CHOIX</th>';*/ echo' </tr> </tfoot> </table> <input type="hidden" id="taille" value="'.$y.'" />'; $var=1; } else $var=0; ?> </center> </body> </html>
Code : 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Stock disponible - Gestion EPI</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #A9EAFE; } --> </style></head> <body> <center> <h2>Choisir le type d'article</h2> <form action="stocke.php" method="POST"><select name="test"> <option value="Ré">Masque à coque FFP1 avec valve <option value="Paire de gant normal plus 27cm T9">Paire de gant normal plus 27cm T9 <option value="Pi">Gant hyflex 11-435 TAILLE 9 COLORIS GRIS CHINE/NOIR <option value="Pa"> PAIRE DE GANT CRUSADER FLEX T9 <option value="Masque">Masque </select> </form> <br><br><br><br> <?php echo("<form action='stocke.php' method='GET'>"); echo("<input type='submit'.value='\valider\'></form>"); ?> <br><br><br><br> <?php // set up DB try { $strConnection = 'mysql:host=localhost;dbname=gestion_epi'; $arrExtraParam= array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); $pdo = new PDO($strConnection, 'root', '', $arrExtraParam); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage(); die($msg); } $query = 'SELECT * FROM epi '; $mes = $pdo->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $mes->execute(); $nbligne = $mes->rowCount();//nombre lignes $nbcolonne = $mes->columnCount();//nombre colonnes if($nbligne>0){ //recuperation nom des colonnes $colums = $mes->fetch(PDO::FETCH_ASSOC); $x=1; foreach($colums as $field_name=>$value) { $col[$x] = $field_name; $x++; } //tableau echo '<table cellpadding="2" cellspacing="2" border="5" class="display" id="lignecommande"> <thead> <tr>'; //titre du tableau for($i=1;$i<$x;$i++) echo '<th>'.strtoupper($col[$i]).'</th>'; echo '<th>CHOIX</th>'; echo' </tr> </thead> <tbody>'; //valeur des lignes $alternate=0; $mes->execute(); $y=0; foreach($mes->fetchall() as $t){ $y=$y+1; if($alternate%2==0){ echo ' <tr id="'.$y.'" class="gradeB">'; for($i=1;$i<$x;$i++){ echo '<td class="center">'.$t[$col[$i]].'</td>'; } echo '<td class="center"><input type="checkbox" name="check'.$y.'" value="'.$t[$col[1]].'"></td>'; echo' </tr>'; } else{ echo ' <tr id="'.$y.'" class="gradeD">'; for($i=1;$i<$x;$i++){ echo '<td class="center">'.$t[$col[$i]].'</td>'; } echo '<td class="center"><input type="checkbox" name="check'.$y.'" value="'.$t[$col[1]].'"></td>'; echo' </tr>'; } $alternate=$alternate+1; } echo ' </tbody> <tfoot> <tr>'; /*for($i=1;$i<$x;$i++) echo '<th>'.strtoupper($col[$i]).'</th>'; echo '<th>CHOIX</th>';*/ echo' </tr> </tfoot> </table> <input type="hidden" id="taille" value="'.$y.'" />'; $var=1; } else $var=0; ?> </center> </body> </html>
Partager