Error in php url

Asked

Viewed 47 times

-3

I have a querystring to work with url.

set_include_path('application' . PATH_SEPARATOR. get_include_path() );

            function getGet( $key ){
                    return isset( $_GET[ $key ] ) ? $_GET[ $key ] : null;
            }
                    $path = ('application');
                    $exe = getGet('exe');
                    if( is_file( ''.$path.'/'.$exe.'.php' ) )
                            include ''.$path.'/'.$exe.'.php';
                    else
                            include ''.$path.'/dash/404.php';

But I’m passing id for url, to generate new pages and I have a div hidden error so.

echo $exibir ? 'block' : 'none';

When I step into the url the error in this way:

if (!isset($_GET["error"]) == "error") {
    $exibir = null;
} else {
    $exibir = "block";
    //var_dump($nome);
}

So in return I have this:

 header('Location: '.$_SERVER['HTTP_REFERER'].'?error=error');

If you make a mistake, go to url error = error then mine query stays

?id=teste?error=error

But returns blank the screen and does not display the error message. When I do not pass the ID for url or create a IDin the link case, it works smoothly but within the query doesn’t work.

  • I don’t understand what the problem is. By the way this link is wrong, it should be ?id=teste&error=error.

  • The error is that I already have a query in the url ? id=test where is the ID created when I step ? error=error, getting ? id=test? error=error the screen turns white and does not run the codeecho $display ? block: 'None';code

  • @Jorgeb. is that his IF is wrong: !isset($_GET["error"]) == "error", is comparing a boolean to == "error". "Typo"

1 answer

0


The first URL parameter has to be passed with ? (interrogation) the others are passed with & (and commercial).

Example:

www.algumacoisa.com.br/index.php? param1=4&param2=9&param3=999&param4=etc...

This if also has problem:

if (!isset($_GET["error"]) == "error") {
    $exibir = null;
} else {
    $exibir = "block";
    //var_dump($nome);
}

It should be something like this:

if (isset($_GET["error"]) && $_GET["error"] === "error") {
    $exibir = null;
} else {
    $exibir = "block";
    //var_dump($nome);
}
  • 1

    This is still wrong: if (!isset($_GET["error"]) && $_GET["error"] === "error"), should be if (isset($_GET["error"]) && $_GET["error"] === "error") ... By the way the === Nor need there, the == already solved, after all is not checking numbers (or differentiate from "possible" "boolean") and if it is some supposed micro-optimization, will not have advantages, is myth ... only works if it is too much data even.

  • @Guilherme Nascimento, yes, thanks was already correcting when commented.

  • Friend thanks, I changed the header('Location: '.$_SERVER['HTTP_REFERER'].'error=error'); to header('Location: '.$_SERVER['HTTP_REFERER'].'&error=error'); it worked correctly, because it was two days already breaking my head, Almost remaking the system to work with database, Thank God bless you!

Browser other questions tagged

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