Bonjour à tous,

J'ai fait un petit bout de code avec 2 boutons qui bascule de la couleur verte à la couleur rouge.
Mon problème :
- Je clique sur le premier bouton : il bascule en rouge --> fonctionnement normal
- Je clique sur le deuxième bouton : il bascule en rouge --> fonctionnement normal, par contre le premier bouton bascule en vert !!! --> problème rencontré il devrait rester rouge

Voici mon code :
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
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="content-type">
        <title>python</title>
 
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <script src="js/jquery-3.3.1.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </head>
    <body>   
        <form method="post">
            <div class="container">
                <div class="row">
                    <div class="col-sm-4">
                        <br>
                        <?php 
                        if (isset($_POST['etatLedR']) && isset($_POST['btnLedR'])) {
 
                            if ($_POST['etatLedR'] == 'on') {
				echo'<input type="hidden" name="etatLedR" value="off" />';
				exec('sudo python3 /var/www/html/Python/python/ledRON.py');
				echo '<button type="submit" class="btn btn-danger" name="btnLedR">Eteindre la LED rouge</button>';
 
			// Si la variable session est OFFR nous éteignons la LED R et affichons le btn en vert
                            } elseif ($_POST['etatLedR'] == 'off'){ 
				echo'<input type="hidden" name="etatLedR" value="on" />';
				exec('sudo python3 /var/www/html/Python/python/ledROFF.py');
				echo '<button type="submit" class="btn btn-success" name="btnLedR">Allumer la LED rouge</button>';
                            }
			} else { 
                            // Nous affichons le btn en vert
                            echo'<input type="hidden" name="etatLedR" value="on" />';
                            echo '<button type="submit" class="btn btn-success" name="btnLedR">Allumer la LED rouge</button>'; 
			}?>
 
                    </div>
                    <div class="col-sm-4">
                        <br>
                        <?php 
                        if (isset($_POST['etatLedV']) && isset($_POST['btnLedV'])) {
 
                            if ($_POST['etatLedV'] == 'on') {
				echo'<input type="hidden" name="etatLedV" value="off" />';
				exec('sudo python3 /var/www/html/Python/python/ledVON.py');
				echo '<button type="submit" class="btn btn-danger" name="btnLedV">Eteindre la LED verte</button>';
 
				// Si la variable session est OFFV nous éteignons la LED V et affichons le btn en vert
                            } elseif ($_POST['etatLedV'] == 'off'){ 
                                echo'<input type="hidden" name="etatLedV" value="on" />';
				exec('sudo python3 /var/www/html/Python/python/ledVOFF.py');
				echo '<button type="submit" class="btn btn-success" name="btnLedV">Allumer la LED verte</button>';            
							}   
                            // Teste si une variable session existe sinon nous affichons le btn en vert
                        } else { 
                            echo'<input type="hidden" name="etatLedV" value="on" />';
                            echo '<button type="submit" class="btn btn-success" name="btnLedV">Allumer la LED verte</button>';
                        }?>
                    </div>
                </div>
            </div>
        </form>
    </body>
</html>
Je vous remercie beaucoup.