Login system giving error!

Asked

Viewed 107 times

-3

I am trying to make a login system, I made the form so that when the button was pressed it sent 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 input the data and give it to Ubmit, this error message appears in Chrome: Arthur.000webhostapp.com is currently unable to fulfill this request.

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

1 answer

2


Your code is many errors, first one is missing ; and in the end:

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

Do so:

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

And this your if is totally wrong:

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

This is not how you use if && || and etc, outside that mysqli_query does not return data, it executes only, what returns data is fetch

Actually this if is not even necessary, the check is already in the SELECT

And at the end of your code is a } leftover:

    }
?>

The header probably won’t work:

header("Location: indexVol.php");

Because header has to come before any content, it is part of the HTTP header, you can exchange it for javascript that works on the front end or use ob_start, in the case how is a simple redirect Javascript should solve.

I also recommend that always check of 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 didn’t make sense) and ifs in php and also learn the basics of mysqli (PHP api to connect in mysql)

Browser other questions tagged

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