良好的错误标记| PHP
对于所有想到error_reporting()函数的人来说,其实不然,我需要的是每当完成MySQL查询时,语句都会像良好的错误标记| PHP,php,mysql,Php,Mysql,对于所有想到error_reporting()函数的人来说,其实不然,我需要的是每当完成MySQL查询时,语句都会像 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..."; } 无论语句是真是假,我都希望在使用header()函数重定向时出现错误,并在页面的某
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...";
}
无论语句是真是假,我都希望在使用header()函数重定向时出现错误,并在页面的某个div中回显错误报告
基本上是这样的:
$error = '';
此部分显示在div标记内
<div><?php echo $error; ?></div>
但这根本不起作用:(您可以使用$\u SESSION superglobal 示例代码:
/* in mysql result checking */
$_SESSION["error"] = "Something wrong happened...";
/* in div tags */
if(!empty($_SESSION["error"])) {
echo $_SESSION["error"];
$_SESSION["error"] = "";
}
我还认为您需要在脚本的开头调用session_start(),如果以前没有这样做的话
致以最诚挚的问候,T.这将不起作用,因为
错误
未在url
中声明。发送位置标头时,您只是丢弃(取消设置)了错误
变量
您应该自己编写错误代码,例如:
0001 = ok
0002 = DB_error
...
并通过GET变量发送它们,在url
中捕获它们并解析它们
header('Location: url?error='.urlencode($error));
请记住,http是一种请求/响应协议。因此,您的脚本使用位置头进行响应(基本上终止),并告诉浏览器向您的应用程序(或url指向的任何位置)发出新请求。$error中的当前值仅在当前请求中可用,而在新请求中不可用。请在将$error粘贴到url地址之前将其包装在urlencode()中。谢谢。;-)
header('Location: url?error='.urlencode($error));