Error 404 in a php file

Asked

Viewed 444 times

0

I’m trying to make a form, created in the index.php file, that sends by method POST for the.php sign-up page and with a header() send a verification variable back to the index.

However, when it goes back to the index.php page, it says that the file was not found and gives Error 404.

index php.:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Exercicio 1</title>
</head>
<body>
<?php
    echo '<form action="cadastro.php" method="post">
            Nome: <input type="text" name="nome" value="" /> <br />
            Email: <input type="text" name="email" value="" /> <br />
            Senha: <input type="password" name="senha" value="" /> <br />
            <input type="submit" value="Enviar" />
        </form>';

    if(@$_GET['login'] == 1){
        echo 'Informe nome novamente!';
    }

?>
</body>
</html>

php.:

<?php
require 'connection.php';
require 'database.php';

$usuario = array(
    'nome' => $_POST['nome'],
    'email' => $_POST['email'],
    'senha' => $_POST['senha'],
    );

if(empty($_POST['nome']) || strlen($_POST['nome']) < 5){
    header("Location:index.php login=1");
}
else if(!strstr($_POST['email'], '@') || strlen($_POST['email']) < 5){
    header("Location:index.php login=2");
}
else if(empty($_POST['senha']) || strlen($_POST['senha']) < 5){
    header("Location:index.php login=3");
}
else{
    DBCreate('usuarios', $usuario);
    header("Location:index.php login=4");
}  ?>

I’m using XAMPP on Windows.

  • 1

    Your header shouldn’t be Location: index.php?login=X, where X is the respective value? In fact, it says that which file does not exist?

1 answer

2


The addresses are incorrect:

header("Location:index.php login=1");
...
header("Location:index.php login=2");
...
header("Location:index.php login=3");
...
header("Location:index.php login=4");

Exchange for:

header("Location:index.php?login=1");
...
header("Location:index.php?login=2");
...
header("Location:index.php?login=3");
...
header("Location:index.php?login=4");

It is worth remembering that the Location is a header from reply HTTP, that is, it is not PHP that redirects and the browser when receiving the headers, so the location: must contain a path relative or absolute to the current page address.

About the use of the arroba:

I noticed you’re wearing @ to suppress "warnings", in case it would be nice to read this:

  • 1

    Aaah, thank you very much, I spent hours reading and had not seen that the "?".

  • 1

    I was giving a Warning on the index, because it said that the variable login had not yet been instantiated, but as I did not need the variable the first time I open the index, I decided to delete that Warning.

Browser other questions tagged

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