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>
</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);
}
?>