Several buttons on the same page with different functions

-1

I have the following code that has 3 buttons, at the push of a button, it should change a value in my table in Mysql, but when I press one of the buttons, it is the same as pressing all the other buttons at the same time time.

Follow the code:

<?php
    include("salvateste.php");

    $QUERYM = "SELECT * FROM botoes";

    $execute = mysqli_query($conexao, $QUERYM);

    $line = mysqli_fetch_array($execute);

    $valor  = $line['b1'];
    $valor1 = $line['b2'];
    $valor2 = $line['b3'];

    if($valor == '1'){
        $est1 = "Ligado";
    } else {
        $est1 = "Desligado";
    }

    if($valor1 == '1'){
        $est2 = "Ligado";
    } else {
        $est2 = "Desligado";
    }

    if($valor2 == '1'){
        $est3 = "Ligado";
        $est4 = "Desligado";
    } else {
        $est3 = "Desligado";
        $est4 = "Ligado";
    }


    ?>
<br>

<center>
<form method="GET" ation="" action="controles.php">
<button class="css_btn_class" type="submit" name="Lamp1">Lampada 1 - <?php echo $est1 ?></button>&nbsp;&nbsp;
</form>
<form method="GET" ation="" action="controles.php">
<button class="css_btn_class" type="submit" name="Lamp2">Lampada 2 - <?php echo $est2 ?></button>
</form>
    <br>
    <br>
    <br>
    <form method="GET" ation="" action="controles.php">
    <button class="css_btn_class" type="submit" name="EE">Energia Convencional - <?php echo $est3 ?><br>
    Energia limpa - <?php echo $est4 ?></button>
</form>
</center>


<?php

include("salvateste.php");

$queryA1 = "UPDATE botoes SET b1='1' WHERE b1 = '0'";
$queryA0 = "UPDATE botoes SET b1='0' WHERE b1 = '1'";

$queryB1 = "UPDATE botoes SET b2='1' WHERE b2 = '0'";
$queryB0 = "UPDATE botoes SET b2='0' WHERE b2 = '1'";

$queryC1 = "UPDATE botoes SET b3='1' WHERE b3 = '0'";
$queryC0 = "UPDATE botoes SET b3='0' WHERE b3 = '1'";

if(isset($_GET['Lamp1'])){
    if($est1 == "Desligado"){
        $est1 = "Ligado";
    } else if($est1 = "Ligado"){
        $est1 = "Desligado";
    }
} 

if(isset($_GET['Lamp2'])){
    if($est2 == "Desligado"){
        $est2 = "Ligado";
    } else if($est2 = "Ligado"){
        $est2 = "Desligado";
    }
} 

if(isset($_GET['EE'])){
    if($est3 == "Desligado" && $est4 == "Ligado"){
        $est3 = "Ligado";
        $est4 = "Desligado";
    } else if($est3 = "Ligado" && $est4 == "Desligado"){
        $est3 = "Desligado";
        $est4 = "Ligado";
    }
} 

 if($est1 == "Ligado"){
 mysqli_query($conexao, $queryA0);
 }else {
 mysqli_query($conexao, $queryA1);
 }   

 if($est2 == "Ligado"){
 mysqli_query($conexao, $queryB0);
 }else {
 mysqli_query($conexao, $queryB1);
 } 

 if($est3 == "Ligado" && $est4 == "Desligado"){
 mysqli_query($conexao, $queryC0);
 }else {
 mysqli_query($conexao, $queryC1);
 } 

 ?>
    
asked by anonymous 18.11.2017 / 19:35

1 answer

1

I do not know if I understand what you want to do. As all actions send to same file (control.php) Make the action with variable in GET like this:

<form method="GET" ation="" action="controles.php?qlamp=lamp1">
<form method="GET" ation="" action="controles.php?qlamp=lamp2">
<form method="GET" ation="" action="controles.php?qlamp=lamp3">

In the file Controle.php you treat the variables as they should be treated

and does this ation="" exist? Is that right?

    
22.11.2017 / 11:18