良好的错误标记|的PHP

前端之家收集整理的这篇文章主要介绍了良好的错误标记|的PHP 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

对于每个想到了error_reporting()函数的人,事实并非如此,每当MySQL查询完成时,我所需要的就是

  1. if($result)
  2. {
  3. echo "Yes,it was fine... bla bla";
  4. }
  5. else
  6. {
  7. echo "Obv@R_403_437@sly,the echo'ing will show in a white page with the text ONLY...";
  8. }

每当语句是对还是错时,我都希望在使用header()函数重定向时出现错误,并在页面上某处的div中回显错误报告.

基本上是这样的:

  1. $error = '';

这部分出现在div标签

  1. <div><?PHP echo $error; ?></div>

因此,使用header()重定向时,将回显错误部分.

  1. if($result)
  2. {
  3. $error = "Yes,it was fine... bla bla";
  4. header("Location: url");
  5. }
  6. else
  7. {
  8. $error = "Something wrong happened...";
  9. header("Location: url");
  10. }

但这只是行不通的:(

最佳答案
您可以使用$_SESSION超全局变量.

样例代码

  1. /* in MysqL result checking */
  2. $_SESSION["error"] = "Something wrong happened...";
  3. /* in div tags */
  4. if(!empty($_SESSION["error"])) {
  5. echo $_SESSION["error"];
  6. $_SESSION["error"] = "";
  7. }

我也认为您需要在脚本的开头调用session_start(),如果以前没有这样做的话.

最好的祝福,
T.

猜你在找的MySQL相关文章