Why is this button not updating in the bank?

Asked

Viewed 47 times

-1

Follow here my code below, what happens is the following, when the user logs it to the chat page, when it goes to that page is made an update in the database to status = 1 that status equal to 1 is my condition to display on the users page so that the T.I technician choose who to meet, all that are with status = 1 will be visible there. But when the user clicks the exit button on the chat page, I want you to update the database with status = 0 again, then in the users page to be answered it will leave, I will put a refresh every 60s on this page to update it. --

--CODE FOR THE SECTION OF THE CHAT PAGE WHERE THE BUTTON HAS LEFT---

<body>
        <div class="contact1">



            <div class="fundo_chat">
                <div class="janela_chat">

                </div>

                <form action="chat.php" method="post"  class="form-chat">  
                    <input type="text" name="mensagem" id="mensagem" placeholder="Mensagem">
                    <tr>

                    <button class="btn btn-primary" type="submit" id="botao-enviar">Enviar</button>

                        <a class="btn btn-primary" href="logout.php" role="button" id="botao-sair">Sair</a>
                    </form>


        </div>
        </div>

    </body>
</html>

--CODE WHERE LOGIN VALIDATION IS DONE, REDIRECTS TO THE PAGE OF USERS WHO IS THE T.I, THE REST OF OTHER SECTORS GO STRAIGHT TO CHAT WHERE AWAITS SERVICE AND WHEN REDIRECTED CHANGES STATUS TO =1, IS CHANGING TO 1 PERFECTLY.--

<?php

session_start();
header('Content-Type: text/html; charset=utf-8');
include("conexao.php");

if(empty($_POST['nome']) || empty($_POST['senha'])){
    header('location:index.html');
    exit();
}

$nome = mysqli_real_escape_string($conn, $_POST['nome']);
$senha = mysqli_real_escape_string($conn, $_POST['senha']);

$query = "select * from usuarios where nome = '$nome' and senha = '$senha'";
$setor = "SELECT setor FROM usuarios";

$result = mysqli_query($conn, $query);
$row = mysqli_num_rows($result);

if($row == 1){
    $_SESSION['nome'] = $nome && $_SESSION['senha'] = $senha;



    while ($verifica_setor = mysqli_fetch_array($result)) {

            $setor = $verifica_setor['setor'];
            if ($setor == "Tecnologia da Informação") {
                header('location: usuarios.php');
            }else{
                mysqli_query($conn, "UPDATE usuarios set status = '1' WHERE nome = '$nome'");


                header('location: chat.php');
            }

    }
}
else {
    echo "<script>alert('USUÁRIO NÃO CADASTRADO OU DADOS INVÁLIDOS!');</script>";
    echo "<script>window.location='index.html';</script>";
    exit();
}
?>

--HERE IS MY LOGOUT, WHERE I START THE SESSION PARAMETER TO TAKE HER OVERALL VALUE THAT HAD TO BE THE NAME TO SEARCH ON THE TABLE, I MADE AN OR DIE TO TEST THE QUERY AND AN ECHO TO SEE WHAT WAS BEING DISPLAYED, AND WHAT DISPLAYS ON ECHO IS THE VALUE = 1, THAT’S WHY THE QUERY DOESN’T WORK THE RIGHT WAY--

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

session_start();

echo $_SESSION['nome'];

mysqli_query($conn, "UPDATE usuarios SET status = '0' WHERE nome = '$nome'") or die ("PARAMETROS NAO ALTERADO");

/*
session_destroy();
header('location:index.html');
exit();*/
?>
  • The formatting of the question is done with Markdown.

1 answer

0

You must correct and order the last code

<?php
/*
session no começo e tudo
*/
session_start();

include("conexao.php");


echo $_SESSION['nome'];
/*
avalora $nome, que nao foi avalorada antes
*/
$nome = $_SESSION['nome'];

mysqli_query($conn, "UPDATE usuarios SET status = '0' WHERE nome = '$nome'") or die ("PARAMETROS NAO ALTERADO");

/*
session_destroy();
header('location:index.html');
exit();*/
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.