Good error warning | Php

For everyone who thought about the error_reporting () function, this is not so, I need it when the MySQL query has been executed, and the instruction has the form

if($result)
{
    echo "Yes, it was fine... bla bla";
}
else
{
    echo "Obviously, the echo'ing will show in a white page with the text ONLY...";
}

Whenever statements were true or false, I want the error to appear when redirecting using the header () function and echo the error messages in the div somewhere on the page.

Basically something like this:

$error = '';

This part appears inside div tags.

<div><?php echo $error; ?></div>

That way, part of the error will be echoed when redirected with a () header

if($result)
{
    $error = "Yes, it was fine... bla bla";
    header("Location: url");
}
else
{
    $error = "Something wrong happened...";
    header("Location: url");
}   

But this just doesn't work :(

+3
source share
2 answers

You can use $ _SESSION superglobal.

Code example:

/* in mysql result checking */
$_SESSION["error"] = "Something wrong happened...";

/* in div tags */
if(!empty($_SESSION["error"])) {
    echo $_SESSION["error"];
    $_SESSION["error"] = "";
}

, session_start() script, .

,
.

+2

, error url. () error .

, :

0001 = ok
0002 = DB_error
... 

GET-, catch'em url .

header('Location: url?error='.urlencode($error));
+1

Source: https://habr.com/ru/post/1741537/


All Articles