Login system giving error! [closed]

-3

I'm trying to make a login system, I made the form so that when the button was pressed it would send to a page with the following code:

<body>
    <?php
      $conexao = mysqli_connect("localhost", "123456", "senha","banco")
    ?>
    <?php 
    // RECEBENDO OS DADOS PREENCHIDOS DO FORMULÁRIO 
    $email  = $_POST ["email"];
    $senha  = $_POST ["senha"];

    mysqli_query($conexao, "SELECT * FROM voluntarios WHERE email = '$email' and senha = '$senha'");
            if (email = '$email' & senha = '$senha') {
                header("Location: indexVol.php");
            } else {
                echo "E-mail e/ou senha errados!";
            }
        }
    ?>


</body>

But when you put the data and submit the submit, this error message appears in Chrome: arthur000webhostapp.com can not fulfill this request at this time.

Does anyone have any idea why? Is something wrong with the code? Thanks in advance.

    
asked by anonymous 25.09.2017 / 20:20

1 answer

2

Your code has many errors, first it's missing a ; and at the end:

$conexao = mysqli_connect("localhost", "....", "....","....")

Do this:

$conexao = mysqli_connect("localhost", "....", "....","....");

And this your if is totally wrong:

if (email = '$email' & senha = '$senha') {

This is not how to use if & || and etc, out that mysqli_query does not return data, it only performs, what data return is fetch

  

In fact this is not even necessary, the check is already in SELECT

And at the end of your code you have a } left over:

    }
?>

The header will probably not work:

header("Location: indexVol.php");

Because header has to come before any content, it is part of the HTTP header, you can exchange it by javascript that works on the front end or use ob_start , in the case as it is a simple JavaScript redirection should resolve.

I also recommend that you always check for executions and connections:

<?php
//$link é a variavel da "conexão"
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* Verifica erros de conexão */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit;
}

$email  = $_POST ["email"];
$senha  = $_POST ["senha"];

// o or die verifica erros na query
$result = mysqli_query($link, "SELECT * FROM voluntarios WHERE email = '$email' and senha = '$senha'") or die(mysqli_error($link));


/* array associativa */
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
    echo '<script>window.location="indexVol.php";</script>'; //Redireciona
}

/* libera a memoria */
mysqli_free_result($result);

/* fecha a conexão */
mysqli_close($link);

And learn the basics of programming logic (since your if did not make sense) and ifs in php and also learn the basics of mysqli (PHP api to connect in mysql)

    
25.09.2017 / 20:26