繁体   English   中英

即使代码成功完成,也会出现500内部服务器错误

[英]500 Internal Server Error Given even though code successfully completes

我有以下PHP脚本,它执行SELECT查询,将结果绑定到变量,根据绑定变量的值运行逻辑,并根据逻辑对表进行另一个UPDATE。 该代码成功运行(我可以在表中看到使用正确的值更新了适当的列),但是大约需要10秒才能从服务器获取响应,响应如下:

“服务器遇到内部错误或配置错误,无法完成您的请求。请通过['私人联系人']与服务器管理员联系,以告知他们该错误发生的时间以及您在此错误发生之前所执行的操作。更多服务器错误日志中可能会提供有关此错误的信息。

此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误错误。”

以下是我的脚本:

include("../../include/session.php");

include('inc.php');

if ((isset($_POST['lotnumberinput'])) AND (isset($_POST['sgref'])) ) {


$sgref = $_POST['sgref'];
$lotnumber = $_POST['lotnumberinput'];

$conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_errno) {
        echo "There was a problem connecting to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
    }

    if (!($sqlget = $conn->prepare("SELECT lotnumber, lotnumber2, lotnumber3 FROM invoicesJan2016 WHERE id = ?"))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
    }

    if (!$sqlget->bind_param("s", $sgref)) {
        echo "Binding parameters failed: (" . $sqlget->errno . ") " . $sqlget->error;
    }

    if (!$sqlget->execute()) {
        echo "Execute failed: (" . $sqlget->errno . ") " . $sqlget->error;
    }


    $sqlget->bind_result($lotnumber1, $lotnumber2, $lotnumber3);

    $res = $sqlget->fetch();

    $sqlget->free_result();

if ($res) {

    while ($res) {


        if ($lotnumber1 == "") {


            if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber = ? WHERE id = ?"))) {
                echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
            }

            if (!$sql->bind_param("ss", $lotnumber, $sgref)) {
                echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
            }


            if (!$sql->execute()) {
                    echo "Execute failed: (" . $sql->errno . ") " . $sql->error;

            } else {

                echo "SG Successfully Added!";
            }


        } else if (($lotnumber1 !== "") AND ($lotnumber2 == "")) {


            if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber2 = ? WHERE id = ?"))) {
                echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
            }


            if (!$sql->bind_param("ss", $lotnumber, $sgref)) {
                echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
            }


            if (!$sql->execute()) {
                    echo "Execute failed: (" . $sql->errno . ") " . $sql->error;

            } else {

                echo "SG Successfully Added!";
            }


        } else if (($lotnumber1 !== "") AND ($lotnumber2 !== "") AND ($lotnumber3 == "")) {


            if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber3 = ? WHERE id = ?"))) {
                echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
            }


            if (!$sql->bind_param("ss", $lotnumber, $sgref)) {
                echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
            }


            if (!$sql->execute()) {
                    echo "Execute failed: (" . $sql->errno . ") " . $sql->error;

            } else {

                echo "SG Successfully Added!";
            }


        } else {

            echo "There are too many lot numbers associated with this SG. Please call IT to request additional space.";

        }

    } // End While.

}//end if


} else {

  echo "SG Number did not save. Please try again.";

}

$sqlget->close();
$sql->close();
$conn->close();

感谢所有帮助,因为我不确定为什么花这么长时间才能得到答复。

谢谢!

感谢您的回复。 我能够确认500 Internal Server Error是由4 MB的响应大小引起的... !!! 这是由逻辑的while循环引起的。 通过删除while并重组页面的逻辑组件,响应明显变小并且运行良好。 下面是代码的更新版本,该代码可以正常运行。 谢谢大家的帮助!!!

我的密码:

<?php

include("../../include/session.php");
include('inc.php');

if ((isset($_POST['lotnumberinput'])) AND (isset($_POST['sgref'])) ) {

  $sgref = $_POST['sgref'];
  $lotnumber = $_POST['lotnumberinput'];

  $conn = new mysqli($servername, $username, $password, $dbname);

  if ($conn->connect_errno) {
        echo "There was a problem connecting to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
  }

  if (!($sqlget = $conn->prepare("SELECT lotnumber, lotnumber2, lotnumber3 FROM invoicesJan2016 WHERE id = ?"))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
  }

  if (!$sqlget->bind_param("s", $sgref)) {
        echo "Binding parameters failed: (" . $sqlget->errno . ") " . $sqlget->error;
  }

  if (!$sqlget->execute()) {
    echo "Execute failed: (" . $sqlget->errno . ") " . $sqlget->error;
  }

  $sqlget->bind_result($lotnumber1, $lotnumber2, $lotnumber3);

  $res = $sqlget->fetch();

  $sqlget->free_result();

  if ($res) {

    if ($lotnumber1 == "") {

      if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber = ? WHERE id = ?"))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
      }

    } else if (($lotnumber1 !== "") AND ($lotnumber2 == "")) {

      if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber2 = ? WHERE id = ?"))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
      }

    } else if (($lotnumber1 !== "") AND ($lotnumber2 !== "") AND ($lotnumber3 == "")) {

      if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber3 = ? WHERE id = ?"))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
      }

    } else {

      $sql = "";

    }

    if (!($sql == "")) {

      if (!$sql->bind_param("ss", $lotnumber, $sgref)) {

        echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
      }

      if (!$sql->execute()) {

        echo "Execute failed: (" . $sql->errno . ") " . $sql->error;

      } else {

        echo "SG Successfully Added!";
      }

    } else {

      echo "There are too many lot numbers associated with this SG. Please call IT to request additional space.";

    }

  }//end if

} else {

  echo "SG Number did not save. Please try again.";

}

$sqlget->close();
$sql->close();
$conn->close();

?>

(已编辑的答案)在尝试通读代码之后( 缩进不正确 ,使阅读变得非常困难),我建议检查您的变量( $sqlget$sql$conn )是否仍然包含类的实例,因此您实际上可以关闭任何东西。

<?php

include("../../include/session.php");

include('inc.php');

if ((isset($_POST['lotnumberinput'])) AND (isset($_POST['sgref'])) ) {

    $sgref = $_POST['sgref'];
    $lotnumber = $_POST['lotnumberinput'];
    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_errno) {
        echo "There was a problem connecting to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
    }

    if (!($sqlget = $conn->prepare("SELECT lotnumber, lotnumber2, lotnumber3 FROM invoicesJan2016 WHERE id = ?"))) {
        echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
    }

    if (!$sqlget->bind_param("s", $sgref)) {
        echo "Binding parameters failed: (" . $sqlget->errno . ") " . $sqlget->error;
    }

    if (!$sqlget->execute()) {
        echo "Execute failed: (" . $sqlget->errno . ") " . $sqlget->error;
    }

    $sqlget->bind_result($lotnumber1, $lotnumber2, $lotnumber3);
    $res = $sqlget->fetch();
    $sqlget->free_result();

    if ($res) {

        while ($res) {

            if ($lotnumber1 == "") {

                if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber = ? WHERE id = ?"))) {
                    echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
                }

                if (!$sql->bind_param("ss", $lotnumber, $sgref)) {
                    echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
                }

                if (!$sql->execute()) {
                    echo "Execute failed: (" . $sql->errno . ") " . $sql->error;
                } else {
                    echo "SG Successfully Added!";
                }

            } else if (($lotnumber1 !== "") AND ($lotnumber2 == "")) {

                if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber2 = ? WHERE id = ?"))) {
                    echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
                }

                if (!$sql->bind_param("ss", $lotnumber, $sgref)) {
                    echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
                }

                if (!$sql->execute()) {
                    echo "Execute failed: (" . $sql->errno . ") " . $sql->error;
                } else {
                    echo "SG Successfully Added!";
                }

            } else if (($lotnumber1 !== "") AND ($lotnumber2 !== "") AND ($lotnumber3 == "")) {

                if (!($sql = $conn->prepare("UPDATE invoicesJan2016 SET lotnumber3 = ? WHERE id = ?"))) {
                    echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
                }

                if (!$sql->bind_param("ss", $lotnumber, $sgref)) {
                    echo "Binding parameters failed: (" . $sql->errno . ") " . $sql->error;
                }

                if (!$sql->execute()) {
                    echo "Execute failed: (" . $sql->errno . ") " . $sql->error;
                } else {
                    echo "SG Successfully Added!";
                }

            } else {
                echo "There are too many lot numbers associated with this SG. Please call IT to request additional space.";
            }

        } // End While.

    }//end if

    if($sqlget != null){$sqlget->close();} 
    if($sql != null){$sql->close();}
    if($conn != null) {$conn->close();}

} else {
    echo "SG Number did not save. Please try again.";
}

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM